annotate Changes @ 99:53899975154c

*** empty log message ***
author kono
date Fri, 14 Mar 2003 21:33:03 +0900
parents 07c2554e1cfa
children a9e6f2a2946f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
59
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
2 Thu Nov 25 17:27:12 JST 1999
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
3
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
4 subroutine call がない
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
5 局所変数もない
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
6 その代わり、大域変数を多用する
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
7 大域変数のスコープは局所的
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
8 Fortran の用に局所変数は静的に取る
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
9 recursion する時には、自分で保存する
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
10 subroutine call時のレジスタのセーブも局所的に行う
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
11 それは、ちょっと変じゃない?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
12 やっぱりデフォルトのフレームは持ち歩くか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
13
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
14 recursive call とそうでないのを区別するか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
15
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
16 fp は用意する方が良い
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
17
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
18 関数定義と同時に、それ専用のfpの構造体を用意する
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
19
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
20 C をcompileする時には、stackを持ち歩く
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
21 fp = (struct func_state *)stack
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
22 えっと、どこに代入するの? そういう問題もあるわけね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
23 じゃあ、fpは特別? それは気に入らないな。static
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
24 なfpにすれば良いわけね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
25
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
26 func(void *stack) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
27 static struct func_state {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
28 static struct func_state *fp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
29 int local1;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
30 brahbrah...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
31 } func_state; // ここまで hidden
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
32 func_state.fp = (stack -= sizeof(struct func_state));
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
33 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
34
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
35 func_state をとってくる演算子があった方が良い? そうね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
36 func.state
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
37 ぐらい?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
38
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
39 fp->local1 みたいなことだけするなら、C と同じになる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
40
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
41 call する時のarguemnt も、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
42 static な func_state に置く
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
43 stack 上の func_state に置く
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
44 という二通りの選択肢がある。Cと互換なら、当然、後者。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
45
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
46 Recursive なら後者だが、この言語は状態遷移を記述するから、static
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
47 なものでも良いはず。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
48
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
49 Internal function は? あってもいいんだけど...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
50
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
51 Recursive call する時には、 fp をsaveする必要があるね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
52 (--(struct func_state *)stack) = fp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
53 call callee(&fp->arg,continuation,stack);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
54 call しても、戻って来ないから... continuation は一般的にはcode
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
55 だから... それは Internal function にするか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
56
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
57 continuation に一般的にcompileする方法を考えないといけないか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
58 self は必要なわけね?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
59
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
60 言語の名前も考えないといかんなぁ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
61
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
62 C からのコンパイラも書かないといけないのか...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
63
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
64 Mon Dec 13 18:53:04 JST 1999
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
65
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
66 compiler based で、内部で partial evaluation できる?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
67
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
68 func をdatabaseとして扱えないなら、それはできない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
69
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
70 しかし、状態遷移としては取り扱える。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
71
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
72 func.state
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
73 func.code
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
74
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
75 みたいな形にしてpartial evaluationすれば良い
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
76
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
77 でも止まるのか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
78
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
79 textual でない、中間的なコード表現があった方が良い? <-> interpreter?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
80
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
81 Prolog ではなんでいけないの? --> Unification が重いから
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
82
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
83 Sat Nov 27 13:50:41 JST 1999
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
84
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
85 func.state とか作るのだったら、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
86 struct {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
87 struct {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
88 int i;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
89 } state;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
90 state *code = {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
91 i = i+1;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
92 };
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
93 } name;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
94 みたいな形で、それ自体を構造化すれば? で、代入すると部分評価される。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
95 代入も可能。なるほど。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
96 *name.code;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
97 値はあるわけ? 値は &state でしょうね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
98 self があれば、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
99 struct {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
100 struct {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
101 int i;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
102 } state,
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
103 *code = {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
104 self->i = self->i+1;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
105 };
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
106 } name;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
107 かな。self = state だよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
108
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
109 union の拡張もあわせて議論すると...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
110
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
111 Partial evalutator をセマンティクスや実行系にいれておくことは可能か?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
112
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
113 byte code とか仮想マシンだったら可能。そうでない場合は?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
114
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
115 いずれにせよ、構造体のタグのunique性を修正しないとだめだな。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
116
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
117 ヘッダファイルはどうするの?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
118
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
119 Mon Dec 13 18:53:18 JST 1999
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
120
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
121 library との整合性は?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
122
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
123 exec sequence では、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
124 (--(struct func_state *)stack) = fp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
125 call callee(&fp->arg);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
126 という形でpointerだけ渡すの? それは変だよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
127
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
128 値渡しにするとすれば、複数の値を渡せたほうが良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
129
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
130 func(void *stack) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
131 static struct func_state {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
132 static struct func_state *fp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
133 int local1;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
134 brahbrah...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
135 } func_state; // ここまで hidden
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
136 func_state.fp = (stack -= sizeof(struct func_state));
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
137 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
138
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
139 の引数自体が、構造体であるべき。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
140
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
141 func(
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
142 struct void *stack
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
143 ) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
144 static struct func_state {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
145 static struct func_state *fp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
146 int local1;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
147 brahbrah...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
148 } func_state; // ここまで hidden
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
149 func_state.fp = (stack -= sizeof(struct func_state));
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
150 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
151
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
152 で、構造体に register storage を許す。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
153
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
154 func(
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
155 static struct argment {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
156 register void *stack;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
157 register void *continuation;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
158 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
159 ) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
160 static struct func_state {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
161 static struct func_state *fp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
162 int local1;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
163 brahbrah...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
164 } func_state; // ここまで hidden
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
165 func_state.fp = (stack -= sizeof(struct func_state));
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
166 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
167
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
168 すると、caller の方も、構造体を引数とするのが自然。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
169
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
170 call caller(
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
171 static struct argment {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
172 register void *stack;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
173 register void *continuation;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
174 } arg = {a,b};
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
175 )
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
176
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
177 みたいな。もちろん、この構造体はインタフェースと呼ばれる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
178
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
179 argument は、callee にあった方が良いけど、caller 側にあっても
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
180 良い。register なんかは、そう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
181
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
182 caller(interface caller_arg = {a,b,c})
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
183 みたいなsyntax かな。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
184 caller->interface = {a,b,c};
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
185 *caller->code;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
186 を、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
187 caller(a,b,c);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
188 と称する。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
189
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
190 function には、interface と code と state があることになる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
191
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
192 state にアクセスする時のlockは? protected state? synchonized state かな?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
193 もちろん、sequential implementatoinでは、そんなものはいらない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
194
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
195 function {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
196 interface:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
197 register int a;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
198 register struct self self;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
199 state:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
200 int b;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
201 serialized int c;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
202 code:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
203 b = a;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
204 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
205
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
206 int にvoid value を定義する。実装は重くなるけど...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
207
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
208 serialzed の semantics は?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
209
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
210 もう少しmicro-Cに近く!
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
211
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
212 carring state と static state。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
213
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
214 Mon Dec 13 19:42:41 JST 1999
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
215
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
216 interface に regsiter keyword を使うのは、あまりに
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
217 実装よりすぎる。でも、でないと状態にできない?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
218 そんなことはないか。やっぱりcaller側のstatic 領域に
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
219 直接書き込む?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
220
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
221 だとCより遅そう。でも、引数に40個とかかかれたら...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
222
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
223 Wed Dec 15 14:09:49 JST 1999
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
224
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
225 C と互換にする?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
226 goto function(argments);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
227 goto *continuation(argments);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
228 みたいな感じで。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
229
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
230 stackの管理は? どうせ、library との互換はとらないと
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
231 いけないんだから...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
232
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
233 local 変数がある場合は stack を動かす。でも、戻す奴がいない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
234 closure 化するか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
235
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
236 return した時の挙動が複雑になる。大域returnするわけだら。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
237
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
238 argments をstatic 領域にかきこむ方式だと互換性がとれない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
239 stack 上の frmae pointer 上にないとダメだから。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
240
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
241 両立させるのは無理か? つまり、これだと、呼び出された方の
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
242 frame semantics は、C と互換になる。だから、stackの直後に
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
243 frame pointer があると思っている (そうか? ) frame pointer
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
244 stack pointer に沿って移動した直後に、そこからのoffset
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
245 で引数を操作することになる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
246
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
247 つまり、それはだめだったことじゃない? つまり、goto だと、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
248 frame pointer は、stack の直後とは限らないから。前の
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
249 frmae pointer 相対に引数にアクセスしてくれれば別だけどね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
250
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
251 stack に引数を積むのは容認して、goto の場合は、向こう側で
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
252 stack を畳むってのは? ということは、普通の関数と定義の
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
253 方法を変えるってことか。ま、悪くはないか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
254
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
255 すると、goto のsemantics は、C と互換になる。それを受ける
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
256 方が異なることをする。それは、なんかおかしいな。それに、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
257 それだと関数呼び出しが軽くならない...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
258
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
259 ということは、やはり、C のcall は、call funciton で
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
260 実現して、その他の呼び出しは、すべて、goto 扱いに
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
261 する方が正しいだろう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
262
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
263 問題は、この言語の関数をcallされた時だな。dual entry にして、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
264 call の時と、goto の時を区別するか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
265 func: stack processing
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
266 func_goto: normal processing
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
267 ...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
268 みたいな感じ。でも、return はないから...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
269
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
270 このあたりも自分で記述できる言語であるべきだよね。その通り。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
271 つまり、C とのstub も自分で記述すると言うことか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
272
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
273 protocol function {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
274 interface c {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
275 register "%esp" struct {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
276 entry code ret(int);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
277 void *fp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
278 } *sp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
279 register "%ebp" void *fp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
280 };
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
281 code function_code {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
282 fp = sp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
283 sp += sizeof(struct local);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
284 struct local *local = sp;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
285
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
286 local->i = 1;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
287 goto *fp->ret(local->i),sp=fp; // return(local->i);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
288 };
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
289 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
290
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
291 みたいな感じでさ。さっすが、アセンブラ。いまいちreturnが汚いけど。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
292 まぁ、return はそのままreturnでもいいけどさ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
293
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
294 あ、これは良いかも知れない。code が複数かけるから。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
295
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
296 state 以外は、consitent state であることを保証しない。ってのは?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
297 local 変数は使っても良いけど、call/goto の前後で、値を保証しないか...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
298
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
299 うーん、だんだん炸裂してるなぁ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
300
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
301 だから、レジスタに対するマッピングの記述と、そうでない部分の
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
302 記述は分離するべきでしょうね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
303
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
304
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
305 全部一辺に実装するわけにはいかないからぁ...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
306
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
307 Thu Dec 16 13:44:21 JST 1999
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
308
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
309 lock は状態遷移レベルで実現するのだから、self などを
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
310 使ってlockする必要はないはず。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
311
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
312 全体の直列化は、状態遷移レベルで、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
313 lock(storage) -> transition
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
314 みたいな形で記述すれば良い。この当たりを、どのように記述するかは
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
315 もう少し先送りしよう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
316
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
317
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
318 引数はレジスタ渡しにしよう。長い引数は、呼び出し側の領域への
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
319 ポインタとする。実装を規定しても良い。そうすれば、varargs
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
320 みたいなものはなくなる。だいたい、なんで、そんなものがいるんだろう?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
321 配列を渡せばいいじゃん。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
322
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
323 なので、引数は一つ(or 二つ)に限るという方法もある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
324
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
325 とすると、やはり、前もって静的領域や動的領域を確保することは
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
326 できない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
327
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
328 この言語では動的領域は自分で確保するわけだから、その点は問題ない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
329
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
330 Thu Dec 16 20:24:55 JST 1999
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
331
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
332 とすると関数呼び出しは、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
333 # register save
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
334 # set 1st argument in register %eax
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
335 # set 2nd argument in register %ecx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
336 # set extra aguments in save area
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
337 # set extra argument pointer in %edx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
338 jmp function
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
339 という形式になるわけね。second を処理するのはめんどくさいから一つ
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
340 にしよう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
341
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
342 えーと、frame pointer はないけど、コンパイルの手順からすると
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
343 あった方が良い。しかし、frame pointer そのものをstatic
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
344 にとるのはまずい。だから、frame pointer がfirst argment
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
345 ということにする方が正しい。とすると引数は、さらに、その
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
346 後と言うわけか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
347 f(fp,argment)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
348 fp を渡すのにさらにargment をレジスタで渡すのはおかしい。おかしいけど、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
349 ま、良いか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
350
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
351 return しないなら、return type の定義をとるのは変だな。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
352
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
353 f(fp,arg1,arg2,arg3) とすると、それぞれが決まったレジスタに入って、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
354 多い分は配列にあると思われる。ふむふむ...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
355 fp->xx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
356 でアクセスすれば、そのまま局所変数になる。全部、配列で
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
357 送っても良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
358
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
359 .set label,value
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
360
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
361 で as は値をセットするようですね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
362
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
363 関数コールの後は戻って来ないから後始末の心配はしなくてよい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
364 frame pointer を使ったら自分で面倒を見ること。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
365
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
366 だと
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
367 a = atoi(s);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
368 みたいなことはできない...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
369
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
370 普通のCの定義と交じると間違いやすい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
371
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
372 とすると、struct と同様に、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
373 protocol
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
374 code
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
375 interface
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
376 state
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
377 を用意するわけね。時間あるのかぁ?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
378
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
379 とりあえず、register 渡しのfunction 定義とgoto文を実装する。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
380
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
381 code name(register "%ebp" void *arg) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
382 goto name(arg);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
383 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
384
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
385 ぐらいかな? で、first argment が必ずregisterにのるようにしないと
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
386 いけない。register storage class を入れて、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
387 register "%ebp" void *arg
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
388 とかするわけね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
389
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
390 ってことは、まず、レジスタを実装しないといけないわけね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
391
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
392 で、stack を使った演算は、一応、そのままにする? それでも動くはず。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
393 式の途中でgotoは使えないんだから、それでいいはず。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
394
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
395 で、それから、これを拡張していく。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
396
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
397 interface c {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
398 register "%ebp" void *arg;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
399 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
400 code name(interface c) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
401 goto name(c.arg); // c. は省略可能
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
402 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
403
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
404 とかね。さらに、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
405
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
406 protocol name {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
407 interface c {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
408 register "%ebp" void *arg;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
409 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
410 code name(interface c) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
411 goto name(arg);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
412 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
413 code name1(interface c) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
414 goto name(arg);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
415 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
416 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
417
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
418 などとするわけか。なんと、これが C と共存するわけね。うーん。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
419
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
420 Fri Dec 31 11:44:03 JST 1999
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
421
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
422 code でなくて、別な名前のほうが良くない? segment? action?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
423
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
424 レジスタ名が入るのは、やっぱりいや。optionalには許す。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
425
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
426 interface は構造体のようなものだから... 構造体でいいんじゃない?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
427 構造体の場合は... malloc する? う、うーん。malloc するとして、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
428 いつfree するの?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
429
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
430 再入するときには、壊れてていいんじゃない? multi-thread でなければね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
431 multi thread では、状態は、レジスタ経由または、thread local に持つ
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
432 必要がある。static は、だから thread local に持たなくてはならない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
433 大域変数に割り振っちゃだめ。でも、いまは、やめて
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
434
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
435 interface は、とりあえず、二つまでの値渡しにしよう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
436 self と arg
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
437 ですね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
438
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
439 もう少し拡張しやすいコンパイラがいいなぁ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
440
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
441 code name (c,a)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
442 struct state *c; struct arg *a;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
443 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
444 goto name(arg);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
445 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
446
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
447 local 変数は? この互換性の問題かぁ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
448
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
449 KL/1 を意識して、interface は heap に置くことにしても良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
450 GC は言語に入れておくべきだが、interfaceは machine independent
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
451 であるべき。だとすれば use/forget みたいものはいるだろう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
452 でも今のところは考える必要はない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
453
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
454 えーと、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
455 code name (c,a)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
456 struct state *c; struct arg *a;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
457 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
458 int i;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
459 goto name(arg);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
460 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
461 の時の一時変数iはどうするの? 基本的にはレジスタ割り当てだけど...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
462 使用させない? んー、大胆な御意見。まぁ、やっぱりheapに割り当てちゃう
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
463 のが簡単か。でも、どうせ抜ける時にはいらなくなるわけだから...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
464
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
465 ほんらい、この変数は、次のcallでは必要無くなるのが普通。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
466
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
467 とにかく、レジスタ変数は必要なんでしょう?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
468
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
469 だから、GC と合わせて言語を設計すべきだよね。API を規定して、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
470 異なるGCを選択できるようにする。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
471
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
472 Sat Jan 1 22:40:22 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
473
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
474 とーにかく、 storage class regisgter を実装しよう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
475
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
476 stmode=REGISTER
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
477
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
478 で、local storage とおなじ扱いとする
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
479 static register? は、ない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
480
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
481 symbol table に storage class をたせば? dsp==EXTRN で判定しているから、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
482 local 変数が36以上あるとおかしくなるぞ?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
483
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
484 sc は GVAR/LVAR だけど、regsiter は LVAR の特殊な奴だから、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
485 sc に入れるほうが正しいか...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
486
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
487 Sun Jan 2 01:47:17 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
488
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
489 register 変数はできました。けど、regsiter を二つ使うと、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
490 一杯になってしまうので、REGISTER6 でコンパイルしないと
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
491 結構ひどい。が、register 変数を%esi,%edi に割り当てれば
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
492 いいか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
493
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
494 Sun Jan 2 04:43:04 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
495
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
496 で、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
497 code name (c,a)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
498 struct state *c; struct arg *a;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
499 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
500 goto name(c);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
501 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
502 の一時変数無しは実装できます。引数は二つまでね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
503
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
504 .file "tmp.c"
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
505 .version "01.01"
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
506 gcc2_compiled.:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
507 .text
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
508 #
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
509 # code name(c,a)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
510 .align 2
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
511 .globl code
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
512 code:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
513 .type code,@function
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
514 # struct state *c; struct arg *a;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
515 # {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
516 # goto name(c);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
517 movl %esi,%esi
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
518 jmp name
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
519 _5:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
520 .size code,_5-code
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
521 .ident "Micro-C compiled"
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
522
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
523 う、すごい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
524
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
525 goto 文がめんどくさい。stack をたたんで、jmp すれば
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
526 よいだけだが..
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
527
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
528 Sun Jan 2 11:17:50 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
529
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
530 普通のcallをcontinuation baseにすることができる?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
531
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
532 Sun Jan 2 20:28:45 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
533
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
534 goto 文だけど、やはり、一度、expr で生成してから、top level
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
535 で jump code を生成しよう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
536
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
537 Tue Jan 4 03:32:55 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
538
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
539 code をtypeにしないと、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
540 code *p;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
541 とか書けないね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
542 int *p();
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
543 と同じだけどさ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
544
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
545
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
546 main(ac,av)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
547 int ac;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
548 char *av[];
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
549 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
550 goto code1(ac,av);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
551 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
552
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
553 code code1(ac,av)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
554 int ac;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
555 char *av[];
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
556 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
557 if (ac)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
558 goto code1(ac,av);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
559 else
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
560 goto ac(ac,av);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
561 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
562
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
563 Tue Jan 4 04:56:56 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
564
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
565 うーん、なんかレジスタにつむ順序が違う
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
566 これは、adecl がreverseにつむから。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
567
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
568 code のretrun
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
569
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
570 やはりcodeはtypeにしないとだめ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
571
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
572 main()
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
573 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
574 goto code1();
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
575 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
576
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
577 とかだと、main に戻って来れない。もちろん、code1() 以降で、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
578 return するわけにはいかない。(main の disp をcode1 は知り得ない)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
579 goto label をcode1の引数に送れば?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
580
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
581 main()
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
582 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
583 goto code1(ret);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
584 ret:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
585 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
586
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
587 これだと、ret がforward labelかどうか分からないけど?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
588
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
589 code1 中で使う中間変数を stack 上にとるのは悪くない。しかし、それを
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
590 %ebp 経由でアクセスするということは、main の中間変数を壊すということ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
591 それを防ぐには、main 中のgoto codeで、%ebp を修正してやれば良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
592 (今は戻って来ないので問題ない)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
593
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
594 code1 のgoto では、戻って来ないから、その必要はない。しかし、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
595 label をcode1 中で渡されると、ちょっと気まずい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
596
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
597 とすると、それは禁止して、main() 中でstackをたたんでからgotoするか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
598 そうすると、無限後退して、結局、帰れないことになる... うーん。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
599
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
600 main() 中のlocal code を許せば、それは解決するが..
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
601
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
602 main()
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
603 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
604 goto code1(code2);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
605 code code2() {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
606 return;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
607 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
608 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
609
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
610 みたいな感じ。でも、そうするとscope rule を変える必要があるので厳しい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
611 ま、悪くはないけどね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
612
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
613 continuation を明示する方法もある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
614
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
615 main()
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
616 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
617 goto code1(continuation);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
618 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
619 code code1(ret)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
620 code (*ret)();
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
621 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
622 goto *ret;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
623 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
624
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
625 かな? call/cc ?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
626
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
627 label へのgotoを許すのもいいけど、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
628 でも、label を許すと、すごくspagettyにならない?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
629
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
630
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
631 Tue Jan 4 11:47:24 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
632
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
633 contiunation じゃなくて、return keyword を使おう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
634 (実際、continuation と少し違うし)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
635 type が少し変になるけど、まあ良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
636
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
637 int
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
638 main()
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
639 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
640 goto code1(return);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
641 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
642 code code1(ret)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
643 code (*ret)(int);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
644 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
645 goto *ret(3);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
646 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
647
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
648 だな。prototype も付けないといけないか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
649
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
650 Tue Jan 4 12:21:44 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
651
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
652 これだとmethodがすべてstatic になってしまう。dynamic なmethod
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
653 呼び出しにするには? dipatcher を自分で作ることになる。かなり
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
654 めんどくさいが...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
655
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
656 code method(obj,arg)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
657 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
658 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
659
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
660 か、あるいは、inline にするか... #define のかわりに inline ねぇ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
661 これはあとで考えて良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
662
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
663 Tue Jan 4 14:22:19 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
664
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
665 main の変数を書き潰すのと、gotgo (*reg)(123) での値は、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
666 register 渡しで、current register にのらないので、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
667 結局、return label は専用に作る必要がある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
668
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
669 Tue Jan 4 18:14:07 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
670
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
671 stack を継ぎ足して、呼び出す方式を取れば、call by value
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
672 のregister 渡しを制限する必要は無くなる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
673
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
674 複数の値を返すことも容易だ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
675
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
676 .file "tmp.c"
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
677 .version "01.01"
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
678 gcc2_compiled.:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
679 .text
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
680 #
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
681 # code name(a,b,c,d,e,f)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
682 .align 2
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
683 .globl code
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
684 code:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
685 .type code,@function
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
686 # struct arg *a,*b,*c,*d,*e,*f;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
687 # {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
688 # int g;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
689 # goto name(a,b,d,e,f);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
690 jmp name
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
691 _5:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
692 .size code,_5-code
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
693 .ident "Micro-C compiled"
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
694
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
695 おお?!
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
696 %esp new %esp = old %esp - 12 -4
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
697 %ebp-4 = g
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
698 %esi = a
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
699 %edi = b
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
700 %ebp = old %esp 0
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
701 %ebp+4 = c code_arg_offset=0
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
702 %ebp+8 = d
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
703 %ebp+12 = e
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
704 %ebp+16 = f
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
705
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
706 interface は付けよう! というか、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
707 goto name(struct {xxxx})
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
708 みたいな感じで良いわけね。どれをregisterにいれるかと言う問題はあるが。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
709
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
710 で、どうやってcallすればいいわけ? emit_pushするかわりにpush
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
711 する?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
712
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
713 うう、これでは、だめか。code argument の数が変わると、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
714 ebp をいちいち動かすことになる。そこにはold sp があるから
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
715 そいつもコピーする必要がある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
716
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
717 %esp new %esp = old %esp - 20
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
718 %ebp-20 = g
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
719 %esi = a
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
720 %edi = b
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
721 %ebp-16 = c code_arg_offset= -16 ((nargs-max_reg)*int_size)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
722 %ebp-12 = d
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
723 %ebp-8 = e
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
724 %ebp-4 = f
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
725 %ebp = old %esp 0
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
726
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
727 そうか、function からcallする時には、local 変数を書き潰して良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
728
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
729 # goto name(a,b,d,e,f);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
730
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
731 %esp new %esp = old %esp - 20
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
732 %ebp-20 = g
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
733 %esi = a
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
734 %edi = b
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
735 %ebp-16 = c code_arg_offset= -16 ((nargs-max_reg)*int_size)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
736 %ebp-12 = d
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
737 %ebp-8 = e
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
738 %ebp-4 = f
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
739 %ebp = old %esp 0 disp=0 (*)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
740 local1 <----16 local variable
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
741 %edx -12 <- disp_offset
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
742 %ecx -8
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
743 %ebx -4
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
744 %ebp = %esp 0
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
745 %eip 4 <- arg_offset
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
746
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
747 となる。ということは、pushl %ebp は、間違い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
748
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
749 だけど、%ebp をそのまま使うのは良くない。disp_offset がかかっているから。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
750 だから、もう一度 pushl %ebp したほうがよい。しかし、push する先は、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
751 上の、(*)。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
752 leave movl %ebp,%esp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
753 popl %ebp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
754 じゃなかったか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
755
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
756 Thu Jan 6 13:00:33 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
757
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
758 できたね。これでとりあえず動くはず。速度は問題だが...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
759 あとは、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
760 ANSI-C prototype
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
761 ANSI-C prototype check
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
762 Interface Definietion
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
763 GC support
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
764 Direct handling of Frame
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
765 だね。簡単に出来そう? たぶん...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
766
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
767 Fri Jan 7 09:42:53 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
768
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
769 goto 文が動いてなかった。あと peep hole optimization version も
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
770 作るか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
771
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
772 continuation として label を送れるようにするべきか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
773 そうすると便利なんだけど、ちょっと、汚いプログラムが
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
774 出来るようになる。あと、送り側の環境(frame)を維持する
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
775 必要がある。ま、できなくはないか...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
776
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
777 そうすると、label が値を持つようになる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
778 a = label:;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
779 とか。うーん。label:(a,b,c) {}; みたいな形で、parallel 代入を許すと言う
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
780 手もあるね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
781
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
782 こちらの方がCとの相性は良いが... main() { label:(){ ... } }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
783 みたいなnestを許すかどうかと言う問題がある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
784 変数の参照を許さなければ、特に問題はない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
785
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
786 a = label: は、二重の意味があるなぁ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
787
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
788 言語の名前。DinnerBell II とか? join も入れる?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
789 code entry_a().entry_b() {}
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
790 ですか? parallel call も?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
791
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
792 Fri Jan 7 19:53:53 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
793
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
794 いまのままだと return が環境を持ってないから、大域脱出できない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
795 まぁ、環境を入れてもいいんだけど、どこに置くかと言う問題が
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
796 あるね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
797
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
798 そうじゃなくて、return 側で判断するか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
799 retrun(ID)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
800 みたいな形でIDで判断する。そうすれば、return 側でID
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
801 を見て判断できる。けど...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
802
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
803 まぁ、はやり、環境を持って歩く方がいいかなぁ。でも、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
804 引き渡しているから、二つ引き渡して、片方を使われたときに、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
805 反対側が消えてしまうのはいたいよね。今のままならば、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
806 そういうことは起こらない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
807
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
808 continuation 特有の問題を避けるなら、このままでもいいんだが...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
809 contrinuation や環境は、このシステムでは自分で作ることが
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
810 できるからね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
811
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
812 そうなんだけど.... retlabel や retcont は実はオブジェクト
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
813 全体に一つあれば良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
814
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
815 引数を渡すときに、そこに環境へのポインタをいれてやれば良いので、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
816 解決は割と簡単だが、そうすると、例の構造体を引数で渡すと言う
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
817 問題を解決する必要がある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
818
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
819 でも、今の実装ならば、まったく同じ変数の構成ならばコピーは
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
820 実際には起こらないわけだから問題ないはず。特に、それを保証するために、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
821 interface を実装する必要がある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
822
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
823 return ->
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
824 (void *)old bp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
825 return address
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
826
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
827 bp を直接操作できるようにするといいんだけど....
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
828
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
829 Sat Jan 8 08:49:59 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
830
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
831 今は、code 内ではreturnできないわけだけど。実は、return って、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
832 code return0(i) int i; { return(i); }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
833 か? 今は禁止してないから書けちゃうよね。どういうcodeが出るんだろう?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
834
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
835 doreturn() では retpending をセットしているだけだから、control=1
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
836 のまま。で、code の終りにくるのでエラーになる。checkret は、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
837 statement の引数で判断するようにしたほうが合理的だろう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
838
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
839 大域脱出は結構根が深いよね。途中をスキップされてうれしいか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
840 destructor と同じで、途中のcodeは全部呼びたいのが普通だろう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
841
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
842 bp が同じになるまで return すれば良いわけだよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
843 return と同じで、明示的に環境を引き渡すようにするか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
844 type は void * で良い?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
845
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
846 return する時にstackの上限を越えているかどうかを自分でチェックする
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
847 必要があるね。誰にreturnするかをcodeで明示すれば良いわけだけど。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
848
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
849 code return0(i) int i; { return(i); }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
850
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
851 を許して、そこで、frame pointer を大域あるいは渡した引数と
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
852 比較して処理する?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
853 code return0(i,env) int i; env *env; {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
854 if (env==self) return(i);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
855 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
856 あれ? これはおかしいよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
857 code return0(i,env) int i; env *env; {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
858 if (env!=self) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
859 env->return();
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
860 return(i);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
861 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
862 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
863 も、なんか変だよなぁ。呼び出しと逆順に帰りたいわけだが...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
864 実際、逆順には帰っているわけだよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
865
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
866 return の中でこそこそ比較するという技もあるけど。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
867
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
868 問題は、destructor に渡す情報だよね。もちろん、self で良いわけだが、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
869 このあたりは、言語外の問題で、それを明示的にしたいから、この言語を
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
870 作っているわけなのだから、これを内部で処理するのはおかしい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
871
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
872 code return0(i) int i; { return(i); }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
873
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
874 これだと、return の型が合わないと言う問題が生じるな。簡単には
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
875 チェックできない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
876 int
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
877 main() {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
878 code a() {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
879 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
880 code b() {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
881 return(i);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
882 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
883 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
884 にすれば、check はできるようになる。でも、これだと、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
885 int
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
886 main() {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
887 a: {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
888 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
889 b: {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
890 return(i);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
891 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
892 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
893 と差がない。module 化を言語外でやるというのが主旨なのだから、これでは
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
894 まずい。これは高級アセンブラなのだから。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
895
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
896 あそうか、return と、大域脱出時のabortとは、状況が違う。だから、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
897 別なcode を呼び出さないとだめ。あるいは、値で区別するか。これは、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
898 logic programming のfail/success と似ている。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
899 main() { } abort { ... }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
900 でもいいけど?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
901 main() { code abort { ... }; code return { ... }}
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
902 かな?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
903
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
904 本来、subroutine call自体が、かなりの省略形なわけだから、これは
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
905 仕方がない。今のままで通常のsubroutine callをシミュレートできるのか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
906 code (struct arg {...},void *sp) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
907 struct env;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
908 push(sp,arg);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
909 push(env,arg);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
910 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
911 できるけど、ちょっと重い。やはり、frame pointer を直接操作しないと
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
912 だめ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
913
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
914 goto 文のほうに、env を一緒に送るものを作ったほうがいいのかも。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
915 goto (*ret)(),environment;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
916 かな。type は? (void *)?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
917 goto ret(),environment;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
918 にはならないの? そうすれば、自分でthreadを制御できる。environment
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
919 の正当性を評価しなくて良いの? まぁ、ねぇ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
920
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
921 これは実装は容易だが... goto といちいち書くのが本当にいいのか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
922 env に対するoperationがあった方がいいなぁ。push とか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
923
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
924 code return0(i) int i; { return(i); }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
925
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
926 を認めれば、return 擬変数はいらなくなる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
927
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
928 でも、実は、return は、caller の引数の数と一致してないといけない
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
929 わけだから、 code return0(i) int i; { return(i); } はだめ。env
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
930 と一致してないといけない。ということは分離するとまずいんじゃない?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
931 あれ? そんなはずないな。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
932
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
933 Sun Jan 9 01:15:56 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
934
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
935 やはり、分離してはまずい。もともと、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
936 goto func(arg);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
937 自体が、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
938 goto func(arg) with current.env
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
939 みたいなものだ。つまり、これは、DinnerBell の、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
940 self message: arg
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
941 と同じ。self->func(arg); でも良い。が、function callと区別が付かないのは
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
942 良くない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
943
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
944 そうすると、type code はsize int でなくなる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
945 code *p = func;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
946 ではいけなくて、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
947 code p = {func,env};
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
948 でないといけない。実際、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
949 goto func(arg)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
950 では、current environment を pushl %ebp でstack = current env
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
951 に積んでいるわけだから。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
952
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
953 いずれにせよ、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
954 struct p = q;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
955 は実装する必要がある。localな、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
956 code p = {func,env};
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
957 も動くはずだが...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
958
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
959 code (*p)();
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
960 goto (*p)(arg);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
961
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
962 はだから少しおかしい。これは、goto がenv を補っていると考えるべき。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
963
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
964 このようにすると、常に、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
965 func,env
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
966 の組をcodeとみなすことになる。これは、object と呼ぶべきだ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
967 ただ、既存のobjectとは別だよな。actor の方が良い?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
968
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
969 うーん、これでjoinを入れれば、完璧なDinnerBellだな。並列送信はないけど。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
970
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
971 Sun Jan 9 01:40:05 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
972
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
973 local 変数の初期化はallocation の後に遅らせる必要がある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
974 nptr に入れられるはずだよね? nptr に初期化フラグを足すか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
975
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
976 文途中で出現するlocal変数の初期化。ちゃんと動いているの?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
977
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
978 構造体のcopyは、lcheck を修正すべきでない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
979
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
980 Sun Jan 9 08:49:43 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
981
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
982 うーん、なんか修正が多いなぁ。あと、関数呼び出し、goto 文の
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
983 構造体への対応か。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
984
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
985 goto (*code)();
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
986
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
987 が、self env を使うのか、code の先の値を使うのかを区別する
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
988 必要がある。もし*を使わないとするとlabel(FNAME)との区別が
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
989 つかないぞ。あ、でも、環境を持ち歩くことにしたから、label
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
990 へもjumpしようと思えばできるね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
991
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
992 並列送信はなくても、この構成ならばstatement単位の並列性を検出するのは
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
993 容易だろう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
994
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
995 やればできるけど、この修正の量だと1日じゃ終らないかなぁ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
996 不動小数点も入れるのでしょう?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
997
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
998 Mon Jan 10 09:00:12 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
999
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1000 引数に構造体を許すには、必ずANSI-Cにする必要がある。難しくは
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1001 ないが...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1002
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1003 goto 文には label, code, continuation の3つが来る。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1004 continuation = code + env
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1005 | label +env
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1006 なのだが、code/label では、env の内容が異なる。できれば面白いが、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1007 その価値はあるのか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1008
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1009 しかし、code , env を分離するとあまりに危険すぎる。どうせgoto
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1010 が危険なんだからいいか? その方が簡単。簡単なら、そっちの方法を
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1011 とるべきじゃない? うーん。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1012
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1013 return の関数依存性はなくした方が良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1014 一つにするのは、pop の問題があるので良くないが...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1015
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1016 そうか、ret をenvを指定して戻るようにしたから、leave する必要は
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1017 なくなった。そして、push %ebp に相当する部分は、lea -disp(%ebp),%sp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1018 で消去されている。ということは、jump のfunction依存部分はいらない
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1019 ということだね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1020
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1021 でも、汚いなぁ。read only属性をhardware supportできればなあ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1022
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1023 sched_yeilds() 相当を書けるかな? lock は?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1024
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1025 一応、できたけど、やっぱり汚い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1026
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1027 Wed Jan 12 16:12:27 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1028
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1029 あは。ANSI prototype はめんどい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1030 bexpr()
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1031 で、関数での引数の順序と、そのあとの宣言の順序が変わることがある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1032 そうすると、うしろの方が優先されてしまう。これは、こまる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1033
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1034 そうか、code_arg_offset のような方法だと、ANSI style では、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1035 困ってしまう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1036
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1037 Thu Jan 13 04:46:12 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1038
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1039 # goto name(a,b,d,e,f);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1040 code name { int g; ...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1041
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1042 %esp new %esp = old %esp - 20
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1043 %ebp-20 = g code's local variable
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1044 %ebp-12 = f <- new_disp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1045 %ebp-8 = d
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1046 %ebp-4 = d
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1047 %ebp-0 = c
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1048 %edi = b
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1049 %esi = a
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1050 %ebp = old %esp 0 disp=0 new env
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1051 local1 <----16 old local variable ( to be erased )
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1052 %edx -12 <- disp_offset
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1053 %ecx -8
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1054 %ebx -4
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1055 %ebp = %esp 0 <- old env
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1056 %eip 4 <- arg_offset
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1057
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1058
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1059 Thu Jan 13 13:38:24 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1060
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1061 だいたいできたけど、test/tmp7.c のprintf のtype mismatch は
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1062 なんなんだろう? ASNI の副作用だろうなぁ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1063
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1064 これだと、プロセスの切替えのときには、結構な量のデータを
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1065 コピーすることになる。それでもいいんだけど...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1066
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1067 それごと、どっかにとって置く。continuationへの参照みたいなもの
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1068 ができないかな。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1069
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1070 コピーができれば、environment/return の組は動くわけだから、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1071 それへの参照と切替えがあっても良いよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1072
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1073 Fri Jan 14 12:03:35 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1074
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1075 Libretto のkeyboardが壊れた... control key が効かない...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1076
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1077 printf の参照の問題は解決しました。list2 がlocalなheap
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1078 に割り当てているのがいけなかったね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1079
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1080 return の処理は、goto 文で処理するより、environment に
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1081 returnto する方が良くはないか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1082
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1083 environment は実は送り先でそれなりの準備が必要。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1084 new-environment() みたいなlibrary があれば、thread にできる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1085
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1086 join は?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1087
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1088 funcall を用意すると良いね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1089
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1090 Mon Jan 17 15:23:34 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1091
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1092 struct aa f1() {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1093 return bb;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1094 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1095
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1096 みたいなのは? 関数の型か代入の型を見て、crn にpointerを渡して、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1097 あとでcopyしてから stack を畳む。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1098
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1099 # bb=f1(aaa);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1100 movl $bb,%eax
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1101 pushl %eax
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1102 movl $aaa,%eax
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1103 pushl %eax
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1104 call main2
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1105 popl %edx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1106 copy %eax,%edx,$400
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1107 addl $400,%esp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1108 # return a1;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1109
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1110 あ、でも、それだと、local変数を返したときに困るね。leave; ret;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1111 してはいけなくて...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1112
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1113 あ、やっぱり、こういう場合はコピー先をmain2に引き渡しているみたいね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1114 void f1(struct aa *ret) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1115 *ret = bb ;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1116 return;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1117 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1118 と同じか。これは簡単。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1119 f1().a[55]
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1120 みたいな場合は、局所変数に強制的に取ってしまうみたいね。それはそうだ...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1121 が、うちの実装だとちょっと厳しいか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1122 leal $-sizeof(struct),%esp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1123 pushl %esp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1124 なんだけど、関数呼び出しの途中ではできないから....
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1125
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1126 # main(ac,av)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1127 # int ac;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1128 .align 2
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1129 .globl main
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1130 main:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1131 .type main,@function
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1132 pushl %ebp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1133 movl %esp,%ebp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1134 pushl %ebx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1135 pushl %ecx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1136 pushl %edx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1137 # char *av[];
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1138 # {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1139 # register int i;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1140 # register char *p;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1141 # int j = 3;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1142 # struct { int b; void (*c)(struct aa); } q = {3,main1},r;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1143 #
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1144 # j = 3;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1145 subl $20,%esp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1146
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1147 このsublを後から指定してやればOk。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1148
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1149 でも、それだと jump の時にずれない? ずれるか? ずれるね。うーん。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1150 実行時にチェックしてやるのも変だし。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1151
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1152 まぁ、それほど必要な機能ではないんだけど。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1153
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1154 これもcontinuationを渡してやると言う手法が使えないことはないんだが...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1155
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1156 関数呼び出しの最初にやってやればいいか。それでできるかな?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1157
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1158
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1159 Sun Feb 20 23:59:16 JST 2000
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1160
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1161 MIPS のcall frame
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1162
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1163 $sp = $fp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1164 local variables
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1165 saved register (including $31 = return address)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1166
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1167 mask は使用したレジスタのbit pattern
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1168 -4 は何?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1169
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1170 18 .mask 0xc0000000,-4
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1171 19 .fmask 0x00000000,0
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1172 20 0000 D0FFBD27 subu $sp,$sp,48
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1173 21 0004 2C00BFAF sw $31,44($sp)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1174 22 0008 2800BEAF sw $fp,40($sp)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1175 23 000c 0000000C move $fp,$sp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1176 24 0010 21F0A003 jal __main
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1177 25 0014 03000224 li $2,0x00000003 # 3
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1178 26 0018 000082AF sw $2,a
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1179 27 001c 04000224 li $2,0x00000004 # 4
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1180 28 0020 00C082AF sw $2,b
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1181 29 0024 05000224 li $2,0x00000005 # 5
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1182 30 0028 000082A3 sb $2,c
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1183 31 002c 06000224 li $2,0x00000006 # 6
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1184 32 0030 08C082A3 sb $2,d
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1185 33 $L1:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1186 34 0034 21E8C003 move $sp,$fp # sp not trusted
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1187 here
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1188 35 0038 2C00BF8F lw $31,44($sp)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1189 36 003c 2800BE8F lw $fp,40($sp)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1190 37 0040 0800E003 addu $sp,$sp,48
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1191 38 0044 3000BD27 j $31
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1192 39 .end main
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1193
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1194 これと同じようにするならば、regiterの使用数を最初に調べる必要が
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1195 あるのだけど、one path compiler である micro-C では、それは
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1196 できない。したがって、enter は後ろでする方が良い。
67
254a0c576114 argument type list
kono
parents: 66
diff changeset
1197
59
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1198 Mon Jan 20 18:25:27 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1199
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1200 3年間さわってないのかよ。何やってんだ?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1201
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1202 goto 文のバグをとらないといけない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1203
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1204 まず、関数引数の構造体の展開。これは、どうってことないはず。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1205
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1206 goto (*code)(i+1,j,...)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1207
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1208 まず、いじらなくてすむ変数を摘出する。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1209
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1210 foreach arg
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1211 compare
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1212
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1213 単純演算 ( op+const , pointer , const assign ) などは、ここで検出する。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1214 大半は、そのようになるはず。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1215 レジスタに乗せる分があるから... それには触らないとして...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1216
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1217 複雑なものは、前もって計算しておく。(get_register する)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1218 スタック上かレジスタ上に作る。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1219
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1220 残りは並列代入となる。再帰的に計算する。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1221
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1222 えーと、大きな順にやるんだっけ? 小さな順にやるんだっけ?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1223 code f( int a, int b, int c ) {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1224 goto g(b,c,a);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1225 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1226 みたいなやつだよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1227
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1228 移動するものを一つ検出する。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1229 そのために移動が必要なものを移動しておく(再帰)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1230 代入する
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1231
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1232 こんなんでいいのか? ループしない? するよね。ループしたら
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1233 get_register する。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1234
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1235 前の例だと、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1236
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1237 g(b,c,a) のbに着目する。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1238 bに代入するコードを出すと、a が壊れる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1239 a が必要かどうかを調べる。それは、引数のリストを見ればわかる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1240 その前に、a を移動する。a の移動先を見て、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1241 空いていれば、移動してOk。しかし、c
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1242 なので、 c を見る。と b になるので、ループするのがわかるので、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1243 b を get_register する。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1244 で、c が移動できる。で、aを移動して、とっておいたbを代入。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1245
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1246 Tue Jan 21 22:45:09 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1247
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1248 とりあえず、jump は複雑すぎる。もっと簡単にすることを考える。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1249 parser 側である程度処理できない?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1250
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1251 goto f(a+3,b(),c);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1252
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1253 などを、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1254
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1255 a = a+3;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1256 b = b();
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1257 goto f(a,b,c);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1258
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1259 程度に簡略化する。この時、f(a,b,c) は(できるだけ)、元の
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1260 関数の引数リストに近付ける。のは無理なので、単純変数
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1261 まで落す。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1262
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1263 あまり関係ないか。一時変数はどうせいるわけだし。ってこと
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1264 みたいね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1265
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1266 だとすると、元のコードと、そう変わらんね。前のも、そんなに
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1267 悪くないってことか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1268
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1269 Wed Jan 22 14:33:12 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1270
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1271 やっぱり、途中で局所変数を増やしたいよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1272
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1273 Fri Jan 31 20:30:36 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1274
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1275 なんか #ifdef / #if がないとだめだな。実装する?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1276 しました。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1277
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1278 Tue Feb 4 01:04:12 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1279
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1280 ## while ((*chptr++ = c = getc(filep->fcb)) != '\n') {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1281 _1120:
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1282 movl $10,%eax
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1283 movl $8,%ecx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1284 movl filep,%edx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1285 addl %ecx,%edx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1286 movl (%edx),%edx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1287 pushl %edx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1288 xchg %edx,%eax .... edx に$10が入る (なんでxchg?)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1289 call getc
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1290 addl $4,%esp
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1291 movl %eax,-20(%ebp) c に代入
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1292 movl $chptr,%ecx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1293 pushl %ecx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1294 popl %ebx
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1295 movl (%ebx),%ecx ecx にchptrの中身
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1296 addl $1,(%ebx)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1297 movb %al,(%ecx)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1298 subl %edx,%eax eax-edx ($10)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1299 je _1119
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1300
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1301 が壊れる理由なんだけど...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1302
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1303 edx,ecx が破壊されちゃうみたいね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1304
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1305 Tue Feb 4 12:17:07 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1306
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1307 ようやっと直したよ...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1308
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1309 use_pointer って、なにもしなくていいんだよね? eax,ebx を避ける
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1310 ってことらしいけど。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1311
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1312 inline/引数付き #define 欲しくない? 置き換えは、local name stack に積んじゃう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1313 展開は function で行う。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1314
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1315 getch を工夫する必要はあるが。置き換えスタックが必要。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1316
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1317
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1318 Wed Feb 5 01:16:00 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1319
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1320 大域で定義された struct field が大域変数と重なっていると落ちる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1321 そりゃそうだけど。どうするの? (直した記憶があるんだけどなぁ...)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1322 struct 毎に field 名とoffset/type の組を持てばい良いんだよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1323
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1324 なんだけど、タグ無しの構造体もあるから、型名の方に付ける必要
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1325 もある。というのは、型名のない構造体もあるから。タグ名には、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1326 一応、リストがついている。なんかに使う必要があったんでしょう
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1327 ね。あ、めんどう。無条件にやっても大域変数名を汚すのを直すの
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1328 が難しい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1329
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1330 ちょっと、あれだけど、「型名.フィールド名」で登録してしまうのはどう?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1331 型名が後で出て来るところが気まずいが...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1332
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1333 def で登録するときに、nptrにdispを代入せずに、struct field list
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1334 (大域変数) に入れて、type の方に、field list (list3(nptr,offset,
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1335 type)) を入れれば良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1336
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1337 あとは、strop の方でtypeのlistを見るようにすれば良いわけだ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1338
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1339 これなら、簡単に直せるはず。LUSTR/GUSTRなどの区別もなくなるし。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1340
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1341 Wed Feb 5 02:10:14 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1342
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1343 浮動小数点ねぇ。完全なANSI Cにするのは大変。でも、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1344 浮動小数点ぐらいないと。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1345
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1346 code generation part を、さらに分割して、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1347 複数のコード対応にしやすいようにする。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1348 おそらく、それほど共有する部分はないけどね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1349
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1350 Sample C code をコンパイルして、その結果から(半分手動で)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1351 Micro CbC code generation part を生成する方法を用意する。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1352
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1353
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1354
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1355 Thu Feb 6 11:47:03 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1356
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1357 Code Segement を単位として使うときに、大域変数はどういう
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1358 ように分けるの? static なんかは意味ないよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1359
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1360 もちろん、自然にグループ分けされるわけだけど。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1361
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1362 あとデータフローだよね。データフローに関しては、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1363 あんまりやってないなぁ
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1364
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1365 Fri Feb 7 14:36:15 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1366
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1367 inline では、必らず、局所変数の増加がある。また、inline
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1368 は普通の関数として展開しておく必要もあるらしい。(何故?)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1369
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1370 #define ねぇ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1371
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1372 #define c(a,b) g(a+1,b+1)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1373 #define g(a,b) printf("%d %d\n",a+1,b+1);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1374
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1375 main() {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1376 int a,b;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1377 a =1; b = 3;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1378 c(a,b);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1379 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1380
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1381 local #define がいるんだよね。g の中で a が出て来た時には、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1382 c のa の置き換えは起こってはいけない。ということは、c
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1383 の置き換えはg が始まる前に終っている必要がある。dynamic
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1384 scope なんだから、assoc の上乗せで良いはず。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1385 macro のlevelを定義して、あるレベルでは、それ以前の展開
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1386 を行わないという手法が良いかな。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1387
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1388 c(a,b) => a=>"a+1", b=>"b+1"
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1389 g(a,b) => (a=>"a+1+1",a=>"a+1"), (b=>"b+1+1",a=>"a+1")
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1390
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1391 みたいな感じ?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1392
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1393 やっぱり関数解析でマクロ処理をやらせるのは無理かな? 先読みされちゃうし。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1394
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1395 Sat Feb 8 00:53:52 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1396
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1397 macro は途中まで書きました。置き換えをマクロが呼び出された
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1398 時点で cheap に置くと、それを解消するタイミングがない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1399 ここだけmallocしても良いが..
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1400
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1401 chptrsave はlistにする必要がある。list で良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1402
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1403 やっぱりmacro levelを見て、自分と一致したassoc valueまで
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1404 手繰って置換するんでしょう。そうすれば、置き換える必要は無い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1405 ということは、local_define にmflagsを格納する必要がある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1406
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1407 c(a,b) => a=>"a", b=>"b"
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1408 a=>"a" .. mflag == 1
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1409 g(a,b) => (a=>"a+1+1",a=>"a+1"), (b=>"b+1+1",a=>"a+1")
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1410 a=>"a+1" .. mflag == 2
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1411
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1412 macro のもとのnptr が残ってないと、オリジナルを返せない。オ
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1413 リジナルは、sc などが破壊されてしまう。ってことは、local macro
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1414 は、local table を汚してはいけないってことだよね。ってことは、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1415 macro table は、もとのとは別に用意する必要がある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1416
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1417 #define c(a,b) g(a+1,b+1)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1418 #define g(a,b) printf("%d %d\n",a+2,b+2);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1419
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1420 main() {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1421 int a,b; a ... local
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1422 a =1; b = 3;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1423 #ifndef a
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1424 c(a, a = "a".. macro mflag==1
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1425 g(a,
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1426 a="a+1" mflag==2
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1427 ^ a = "a" mflag==1
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1428 While replacing a in g's body, a should not
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1429 be replaced to (original) "a", should be c's a.
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1430 b);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1431 /* 3,5 expected */
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1432 #endif
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1433 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1434
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1435 うーむ。ややこしい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1436
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1437 main()
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1438 c(a,b) mflag++
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1439 a=>"a" mflag ==1
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1440 g(a,b) mflag++;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1441 a=>"a+1" mflag ==2
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1442 ^ is replaced by c's "a" not g's a;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1443 いったん mflag level n で展開したら、それは mflag level n-1 となる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1444
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1445 Sat Feb 8 18:13:43 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1446
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1447 いちおう、mflag まではデバッグしたが.... mflag を戻してないんじゃないの?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1448
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1449 ---c(a,b)----------------------- mflag ==1
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1450 a=>hoge, b=>hoga (mflag==1)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1451 ----g(ac,bc)----------------- mflag ==2
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1452 ac=>goge, bc=>goga(mflag==2)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1453 ----printf(a,b)---------- mflag ==3
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1454 a=>poge, b=>poga(mflag==3)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1455
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1456 g が呼び出されると、ac,bc は mflag==1 でのみ置換される。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1457
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1458 あるテキストを置き換えると、それは置き換えたマクロのmflag level
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1459 (つまり一つ少ないレベル)になる。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1460 置き換え終ったら、元のlevelに戻す。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1461
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1462 mflag==2のlevel では、mflag==2のlocal macroの展開しかしない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1463
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1464 置き換えると、mflag level 1 になるので、そこで mflag==1 のlocal
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1465 macro を展開する。mflag==0 は常に展開を行う。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1466
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1467 Sun Feb 9 11:35:23 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1468
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1469 うーん、なんかtypeが、list とCHARなどと入混じっているじゃん。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1470 int save = chptrsave;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1471 で、chptrsave が、$chptrsave になってしまう。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1472
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1473 Sun Feb 9 22:33:36 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1474
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1475
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1476 #define car(e) (heap[(int)(e)])
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1477 #define cadr(e) (heap[((int)(e))+1])
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1478 car(cadr(e))
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1479
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1480 だろ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1481 car ->
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1482 #define e cadr(e) (mleve=1)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1483 cadr ->
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1484 #define e e (mleve=2)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1485
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1486 むぅ。これ、うまくいかないんじゃん。こまったなぁ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1487
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1488 #define c(a,b) g(a+1,b+1)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1489 #define g(a,b) printf("%d %d\n",a+1,b+1);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1490 c(a, b);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1491
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1492 こっちもだめじゃん。ふーむ。lisp interpreter のように
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1493 作ればいいはずなんだけど。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1494
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1495 Mon Feb 10 08:10:25 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1496
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1497 結局、list base のinterpreter を実装しました。きちゃないが。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1498 前の方法でも、頑張ればできるんでしょうけどね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1499
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1500 Tue Feb 11 13:50:03 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1501
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1502 struct copy だけど... 関数がstructを返すときに、引数に前もって
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1503 積んでおくのでは、そこに値がコピーされてしまうし、あとで、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1504 スタックをたたんで置くときにきまずい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1505
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1506 function call の時に、引数の型のチェックをしてない
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1507
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1508 type に -1 とheapの引数が混在しているやつだけど..
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1509 やっぱまずいんじゃないか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1510
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1511 temproal struct は再利用できるんだけど、dispの変更ができないので
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1512 新しく作るしかない。大きいときだけ新しく作るなんていうセコイ
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1513 技はあるけど。(そうすると、帰って来た値へのポインタを使えなく
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1514 なるが.... 別にいいよね。戻り値それ自身を直接 return する
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1515 時もだいじょうぶなはず)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1516
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1517 結局、呼出側で、領域を確保して引き渡すことにしました。この方法だと、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1518 代入のときに二度コピーする必要もない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1519
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1520 register を使用しているかだけじゃなくて、実際にcreg/dregに
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1521 値があるかどうかを記憶する必要がある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1522
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1523 Wed Feb 12 11:09:22 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1524
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1525 それだけどさ... やっぱりアドホックに実現するのは難しいんじゃないの?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1526
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1527 まぁねぇ。register の場所の確保と、寿命は別だから、それで
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1528 いいんだけど、regs flag だけでなんとかならないのかな。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1529 こういう変更ははまるが虚しい。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1530
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1531 Thu Feb 13 18:37:36 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1532
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1533 さて、そろそろ jump にとりかかりますか。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1534
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1535 構造体の引き渡しのシークエンスに使う局所変数の位置がgccと違う...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1536
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1537 そろそろ register は構造体にすべきだね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1538 struct register {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1539 int used;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1540 int valued;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1541 char *name;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1542 char *wname;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1543 char *bname;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1544 int type; /* register variable or not */
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1545 int number;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1546 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1547 virtual/real は、どうする。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1548
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1549 Sat Feb 15 14:00:03 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1550
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1551 fdecl_struct を構文的に引数が出現するときに行うと、int *f(int
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1552 a) などで、* の評価が終る前に、int aが評価されしまう。*obj
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1553 のobj を評価し終らないとfのタイプが確定しない。int*f()[] み
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1554 たいな場合があるから。(?) なので、gcc と、そろえるためには、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1555 arg の先頭で fdecl_struct を行う方法ではだめで、fdecl 中であ
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1556 とから修正する方が良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1557
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1558 fix しようにも引数リストなんて、存在しないじゃん!
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1559
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1560 varargs を実装するのはめんどくさかろう...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1561
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1562 rvalue(expr(),type) では、expr() のtypeをrvalueに引き渡せな
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1563 い。でも、type を大域変数にすると、rvalueを異なるタイプで呼
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1564 び出すときにtypeを変更する必要がある。このrvalueのtype の扱
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1565 いは、かなりはまったことがあるので、rvalue(int e,int type)の
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1566 方が良いことは確かなんだが...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1567
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1568 struct_push のregisterの扱いが複雑すぎ。なんか、もっと
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1569 簡単にならないの?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1570
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1571 Sun Feb 16 07:58:23 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1572
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1573 代入しなくて良いからと言って、ソース
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1574 のリストから除いては、上書きを防げない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1575
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1576 Sun Feb 16 22:55:58 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1577
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1578 vdisp ってなんだったんだ?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1579
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1580 Mon Feb 17 12:35:39 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1581
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1582 並列代入は出来たみたい。代入は小さいものを先にすべきなのか?
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1583 まぁ、できりゃいいんだけど、横に避けるものが大きいのはいや
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1584 だよね。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1585
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1586 Tue Feb 18 11:56:10 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1587
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1588 overraped 用の emit_copy
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1589 float/double
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1590 long long
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1591
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1592 Tue Feb 18 19:34:31 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1593
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1594 code argument の符号を反転させると、list2(LVAR,offset)
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1595 のoffsetがアドレスの方向と一致しているという前提が
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1596 崩れる。それで、構造体の格納順序がずれてしまう...
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1597
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1598 ということは... def(n) でcodeの時はargumentは、局所変数と同じ
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1599 扱いでマイナス符号で処理した方が良い。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1600
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1601 できたみたい。でもさ、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1602
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1603 int main( int ac, char *av[])
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1604 {
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1605 int n;
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1606 goto arg1(0,1,2,3,4,return,environment);
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1607 }
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1608
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1609 って、きっと return 文がないと、文句を
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1610 言われるよね。むむむ。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1611
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1612 post processing する時にoverrapしてないという保証がない。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1613
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1614 Wed Feb 19 15:38:55 JST 2003
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1615
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1616 自分自身とのoverrrapを見てないので、
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1617 struct a a,int i
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1618 int i,struct a a
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1619 みたいな時に自分自身を壊してしまう。なので、emit_copy
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1620 が、ちゃんと方向を見て壊さないように処理する必要がある。
eeca07d1b1c2 *** empty log message ***
kono
parents:
diff changeset
1621
75
92dcf107a837 c code output
kono
parents: 73
diff changeset
1622 call bcopy でいいじゃん。まね。
64
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1623
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1624 Wed Feb 19 20:42:07 JST 2003
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1625
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1626 楊さんの C2CbC と CbC2C を、micro C に取り込む。各所に、
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1627 conv->func(); を埋め込む。conv は、構造体。
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1628
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1629 conv: original
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1630 c2cbc
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1631 cbc2c
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1632
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1633 とする。なるほど。
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1634
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1635 Thu Feb 20 05:34:58 JST 2003
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1636
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1637 むぅ。code-ia32 で結構はまった。あと、stack のアライメントが
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1638 ずれるみたい。6809では問題にならなかったんだけどね。
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1639 leave で調整するべき。
262c8059e5df *** empty log message ***
kono
parents: 59
diff changeset
1640
66
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1641
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1642 Thu Feb 20 14:42:46 JST 2003
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1643
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1644 c2cbc,cbc2c なんだけど、いったん、構文木にしてから変換すると、
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1645 結構失われる情報があるけど、いいの? 特に局所変数の名前とか型
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1646 の情報とか。macro もそうだけど。 indent ぐらい保存できないか
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1647 なぁ。式の途中でfunction callする場合も取り扱う必要があるの
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1648 で、構文木にしてから計算するしかないかな。gexpr の代わりに生
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1649 成するようにするか。そうすると、修正するのは、statement と、
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1650 gexpr になる。でも、結局、構文木で型を持ち歩くしかないんじゃ
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1651 ないの? やっぱり変だよ。型の情報がないのは。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1652
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1653 そうではなくて、exprN() で変換していく方法もある。この方が
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1654 情報が欠落しないので楽だろう。そうすると、修正するのは、
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1655 exprN(),doXXXX()
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1656 となる。これは、量は多い。けど、まぁ、それだけ。この方が
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1657 オリジナルを保存しやすい。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1658
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1659 中間変数を途中で追加すると、宣言部を前もって出力できなく
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1660 なる。{int a;...} を認めれば良いわけだど。実装は難しくない。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1661 じゃ、やれば? でも、汚くなるなあ。出力をいったんバッファ
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1662 に貯めれば? どこに? cheapp ですか? 中間変数はいらないん
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1663 じゃないの?
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1664 a = g(i)+a;
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1665 でしょ。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1666 goto g_1(i,f_1,save_a); }
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1667 code g_1(i,f_1,save_a) { .... goto f_1(ret_value,save_a); }
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1668 code f_1(ret_value,save_a) { a = ret_value+a; ...}
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1669 じゃん。いらないじゃん。。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1670
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1671
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1672 型を表示するルーチンが必要だね。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1673
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1674 めんどくさいなぁ。CbCのProlog version とかほしいなぁ。そうすれば、
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1675 変換は簡単。でも、やろうとしてできなかったことでもあるな。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1676
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1677
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1678 Thu Feb 20 21:13:23 JST 2003
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1679
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1680 MC6809 の mc-codegen.c version は? (ちょっと虚しすぎる?)
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1681 X と D で、use_data_register, use_pointer してやる。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1682 tosop で、X と D の間の足し算を特別扱いする。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1683 (なるほど...) MAX_MAX=0でうまく動くのか? やっぱり、1は
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1684 いるよね。できれば、2だよね。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1685
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1686 結構、浮動小数点も簡単かも。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1687
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1688 汎用の書き換えツールも便利そう。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1689
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1690 でも、Prolog version ってのも面白そう。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1691 code(name,interface(....)) :-
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1692 p()....,goto(name,interface(....)).
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1693 みたいな感じ? 結構、簡単にinterpreterを書けるかも知れない。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1694 これは、あれだね。thread diagram interpreter と似ている。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1695
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1696 Fri Feb 21 13:34:17 JST 2003
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1697
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1698 構文要素での書き換えだけど、どれくらいの能力があるの?
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1699 その場での書き換えだけだと、ちょっと低すぎない? それで、
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1700 cbc2c,c2cbc はできるとは思う。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1701
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1702 まぁいいけど.. chk を無視しているところが結構あるんですけど。
0b068058dd67 *** empty log message ***
kono
parents: 64
diff changeset
1703 jmp,enter,leave ...
67
254a0c576114 argument type list
kono
parents: 66
diff changeset
1704
254a0c576114 argument type list
kono
parents: 66
diff changeset
1705 Sat Feb 22 13:05:04 JST 2003
254a0c576114 argument type list
kono
parents: 66
diff changeset
1706
254a0c576114 argument type list
kono
parents: 66
diff changeset
1707 type の印刷かぁ...
254a0c576114 argument type list
kono
parents: 66
diff changeset
1708
254a0c576114 argument type list
kono
parents: 66
diff changeset
1709 conv 系は大半はdefault convが呼ばれる。なので、c.c
254a0c576114 argument type list
kono
parents: 66
diff changeset
1710 っていうよりは、default.cだよね。必要なところだけ、
254a0c576114 argument type list
kono
parents: 66
diff changeset
1711 自分で代入すると言う方法が良いだろう。その方が
254a0c576114 argument type list
kono
parents: 66
diff changeset
1712 ヘッダも一つで済むし。もちろん、object 指向なら
254a0c576114 argument type list
kono
parents: 66
diff changeset
1713 簡単なんだが...
254a0c576114 argument type list
kono
parents: 66
diff changeset
1714
254a0c576114 argument type list
kono
parents: 66
diff changeset
1715
254a0c576114 argument type list
kono
parents: 66
diff changeset
1716 Sun Feb 23 19:47:41 JST 2003
254a0c576114 argument type list
kono
parents: 66
diff changeset
1717
254a0c576114 argument type list
kono
parents: 66
diff changeset
1718 struct のtypeを印刷するんだけど、一回印刷したら、あとは印刷
254a0c576114 argument type list
kono
parents: 66
diff changeset
1719 しない方が良い。逆に毎回書くなら、tag名type名は、いらないの
254a0c576114 argument type list
kono
parents: 66
diff changeset
1720 か。
254a0c576114 argument type list
kono
parents: 66
diff changeset
1721
254a0c576114 argument type list
kono
parents: 66
diff changeset
1722 とするとtypeの解釈はやめてndeclで処理する? 印刷では、それで
254a0c576114 argument type list
kono
parents: 66
diff changeset
1723 いいわけだけど。
254a0c576114 argument type list
kono
parents: 66
diff changeset
1724
254a0c576114 argument type list
kono
parents: 66
diff changeset
1725 このタイプの印刷だと再帰型は印刷が終了しないんじゃないか?
254a0c576114 argument type list
kono
parents: 66
diff changeset
1726 しないね。
69
dba8d111b7a0 c output
kono
parents: 67
diff changeset
1727
dba8d111b7a0 c output
kono
parents: 67
diff changeset
1728 Mon Feb 24 02:31:06 JST 2003
dba8d111b7a0 c output
kono
parents: 67
diff changeset
1729
dba8d111b7a0 c output
kono
parents: 67
diff changeset
1730 strings の\nなどを元に戻す必要がある。
dba8d111b7a0 c output
kono
parents: 67
diff changeset
1731
dba8d111b7a0 c output
kono
parents: 67
diff changeset
1732 なんか括弧がわやになってるな。
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
1733
2e84590720a6 typedef name
kono
parents: 69
diff changeset
1734 Mon Feb 24 11:02:07 JST 2003
2e84590720a6 typedef name
kono
parents: 69
diff changeset
1735
73
2f613f0ef130 *** empty log message ***
kono
parents: 72
diff changeset
1736 typedef されたタイプは、そちらを使う方が良い。けど、情報が失
2f613f0ef130 *** empty log message ***
kono
parents: 72
diff changeset
1737 われてしまっているので、どこかにとっておかないとだめだね。dsp
2f613f0ef130 *** empty log message ***
kono
parents: 72
diff changeset
1738 ?
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
1739
73
2f613f0ef130 *** empty log message ***
kono
parents: 72
diff changeset
1740 うーむ、これはなかなか難しい。全サーチしてもいいんじゃないか
2f613f0ef130 *** empty log message ***
kono
parents: 72
diff changeset
1741 な。遅いけど。少なくともgnptrで定義されたものはサーチすべき
2f613f0ef130 *** empty log message ***
kono
parents: 72
diff changeset
1742 でしょう。
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
1743
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
1744 indirect function type の表現がなぁ....
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
1745
73
2f613f0ef130 *** empty log message ***
kono
parents: 72
diff changeset
1746 sdecl ではconv を行うので、type_print ではsdeclを経由した場
2f613f0ef130 *** empty log message ***
kono
parents: 72
diff changeset
1747 合に表示を行ってはいけない。
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
1748
73
2f613f0ef130 *** empty log message ***
kono
parents: 72
diff changeset
1749 なんか関数の引数の型の値が微妙に変わるんですけど... やだなぁ...
75
92dcf107a837 c code output
kono
parents: 73
diff changeset
1750
92dcf107a837 c code output
kono
parents: 73
diff changeset
1751 まだ、関数定義のtypedefがstructに変わってしまう。gtypedefed
92dcf107a837 c code output
kono
parents: 73
diff changeset
1752 がうまく動いていない?
92dcf107a837 c code output
kono
parents: 73
diff changeset
1753
92dcf107a837 c code output
kono
parents: 73
diff changeset
1754 Mon Feb 24 17:24:31 JST 2003
92dcf107a837 c code output
kono
parents: 73
diff changeset
1755
92dcf107a837 c code output
kono
parents: 73
diff changeset
1756 まぁねぇ。やっぱり完全に構文木から再構成した方が
92dcf107a837 c code output
kono
parents: 73
diff changeset
1757 便利ではあるよね。特に getsym (空白など)と conv->x_()
92dcf107a837 c code output
kono
parents: 73
diff changeset
1758 との総合作用はめんどくさい。
92dcf107a837 c code output
kono
parents: 73
diff changeset
1759
92dcf107a837 c code output
kono
parents: 73
diff changeset
1760 そのためには、局所変数名をtree上で持ち歩く必要がある。
92dcf107a837 c code output
kono
parents: 73
diff changeset
1761 まぁ、そうすれば良いだけだけど。
92dcf107a837 c code output
kono
parents: 73
diff changeset
1762
92dcf107a837 c code output
kono
parents: 73
diff changeset
1763 実際、今のセットで出来るかどうかは、ちょっと怪しい。
92dcf107a837 c code output
kono
parents: 73
diff changeset
1764 たぶん、buffer に出力するってのをいれればおそらくは
92dcf107a837 c code output
kono
parents: 73
diff changeset
1765 変換できるだろう。
92dcf107a837 c code output
kono
parents: 73
diff changeset
1766
76
fb3fb9e9a462 *** empty log message ***
kono
parents: 75
diff changeset
1767 式の途中での呼び出しとかを考えると、やっぱり
fb3fb9e9a462 *** empty log message ***
kono
parents: 75
diff changeset
1768 構文式から生成しないとだめだろうね。
fb3fb9e9a462 *** empty log message ***
kono
parents: 75
diff changeset
1769 (ってことは、まだ、かなりの作業があるってこと.... むぅ...)
fb3fb9e9a462 *** empty log message ***
kono
parents: 75
diff changeset
1770 tmp2.c は、通らないし...
78
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1771
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1772 Fri Feb 28 20:32:46 JST 2003
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1773
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1774 で、c2cbc は、途中で float の方を先にやるわけ?
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1775
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1776 Sat Mar 1 22:05:43 JST 2003
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1777
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1778 creg_destroy は、ぜんぜんだめ。これは基本的なアイデアがだめ。
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1779
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1780 long long はstructでいいんじゃない? だめ? で struct 演算を別に
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1781 定義してやる。これは、実装にもよるか。
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1782
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1783 float,long longなんだけど、
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1784 FRGVAR DRGVAR LRGVAR
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1785 などを作る。さらに、
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1786 FMUL DMUL LMUL
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1787 などもいる。型の変換は binop で解釈する。変換も演算になる。
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1788 D2F, D2I, F2D, F2I, I2D, I2F, U2D, U2F
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1789 ぐらいですか?
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1790
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1791 emit_pushは、型を必要とするけど? そうだねぇ。emit_fpush, emit_dpush
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1792 かな?
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1793
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1794 creg にfloat register(or stack) の値を入れればいいんじゃないの?
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1795 それを見て、emit_pushの型を決める。creg は、けっこう、いろんあ
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1796 ものが見ているので、いじらない方がいいじゃないかなぁ。
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1797 そうね。FMULとかがあるなら、それで判断できそう。
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1798
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1799 構文木には型を含めないってのは不便。型を入れれば? そうすれば、
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1800 RGVAR CRGVAR FRGVAR DRGVAR LRGVAR
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1801 ではなく、
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1802 RGVAR
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1803 ですむし。その方が変形も楽だしね。型は、
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1804 CHAR,UNSIGNED, UNSIGNED CHAR, INT, FLOAT, DOUBLE, LONGLONG
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1805 ぐらいですか。
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1806
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1807 emit_data
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1808
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1809 とすると、書き換えが結構あるけど。
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1810
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1811 Sun Mar 2 12:58:38 JST 2003
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1812
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1813 あとはconstantだね。FCONT,DCONSTかな。binopでは
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1814 変換とかも必要なわけだけど。
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1815
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1816 そういえば、shot のload/storeもないね。SRGVAR,SASSとかですか? SASS
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1817 は、すでにあるなぁ。
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1818
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1819 Sun Mar 2 22:01:58 JST 2003
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1820
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1821 あれ?
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1822 conv->_sm();
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1823 (*conv->_sm)();
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1824 の場合は、
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1825 *conv->_sm の値へcallする
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1826 んだけど、
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1827 goto exit1();
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1828 goto (*exit1)();
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1829 の場合は、
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1830 exit1
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1831 の値へjumpするんだよね? およ? なんか勘違いしてる? なんでexit1()
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1832 だとindirectが出て、(*exit1)だと出ないんだろう?
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1833
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1834 この宣言は、
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1835 void (*_sm)();
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1836 であって、
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1837 void _sm();
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1838 はできない? なんで?
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1839
8418d4b7caa7 *** empty log message ***
kono
parents: 76
diff changeset
1840 あぁ、まぁ、いろいろ、めんどくさい。
79
82d0e30f61dd *** empty log message ***
kono
parents: 78
diff changeset
1841
82d0e30f61dd *** empty log message ***
kono
parents: 78
diff changeset
1842 やっぱり、arglist の再帰的扱いがちゃんとしてないとだめ。
81
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1843
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1844 うーむ、 enum なんてのもあるのね。やさしいけど、いるのか?
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1845
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1846 code (code *) * みたいなのがあるので、conv は手直しが必要。
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1847
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1848 Mon Mar 3 12:38:08 JST 2003
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1849
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1850 float/duble は順調に進んでるけど、3日はかかるでしょう。
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1851
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1852 binop を書いちゃうとmc-parse.c は、ほとんど終り?!
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1853 代入と関数呼び出しが残っているか。あと single もあるね。
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1854
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1855 emit_push base で書くんだけど、他のCPUではだいぶ様相が
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1856 違うんだろうな。
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1857
f94ca1168520 float first try...
kono
parents: 79
diff changeset
1858 dreg/creg のfloating versionが必要です。( です? )
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1859
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1860 Tue Mar 4 14:56:28 JST 2003
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1861
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1862 double のcurrent register は387のスタックを使う。(?)
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1863 関数呼び出し時に387のスタックが保存されるという
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1864 保証は無いので、emit_dpushでは、%esp に保存する。
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1865
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1866 でも、そうすると、代入の後などで387のスタックが
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1867 常に残ることになる。こいつをクリアするコードは
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1868 どこにいれる? free_register でもいいんだけど....
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1869 ううーむ、つかいずらいやつ。ld じゃなくて、
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1870 stack top に代入するオペレーションはないの?
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1871
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1872 (あぁ、でも、なんか、floatは、もうすぐ終っちゃうな... なんか、
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1873 さびし...)
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1874
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1875 Tue Mar 4 23:58:07 JST 2003
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1876
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1877 fmulp とかでは、fpp のstackのつじつまはあう。fstl とかだと、
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1878 合わない。fstpl すればいいんだが、そうすると連続代入でまずくなる。
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1879 値を使うかどうかを代入時に知ることができれば良いんだが。
85
3789aef7331d minor fix
kono
parents: 82
diff changeset
1880 (use flag で判断することにした)
82
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1881
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1882 結局、freg は、使わなかったね。0が、入っているので直さないとまずいか。
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1883 fregを見て、stack を直すってのは、やっぱり、まずいよな...
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1884
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1885 でも、浮動小数点レジスタを持つCPUの場合はいるんじゃないの?
25654dc29ecc First Floating Point coding done.
kono
parents: 81
diff changeset
1886
85
3789aef7331d minor fix
kono
parents: 82
diff changeset
1887 Wed Mar 5 11:25:11 JST 2003
3789aef7331d minor fix
kono
parents: 82
diff changeset
1888
3789aef7331d minor fix
kono
parents: 82
diff changeset
1889 printf では 引数はdoubleで統一する必要がある。goto() では、
3789aef7331d minor fix
kono
parents: 82
diff changeset
1890 それをするのはまずい。局所変数と同等だから。ってことは、
3789aef7331d minor fix
kono
parents: 82
diff changeset
1891
3789aef7331d minor fix
kono
parents: 82
diff changeset
1892 関数の引数はdoubleにしないとだめなのね。プロトタイプが
3789aef7331d minor fix
kono
parents: 82
diff changeset
1893 ある時は、その限りでない。(うーむ...)
3789aef7331d minor fix
kono
parents: 82
diff changeset
1894
87
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1895 (くそ、こいつの副作用が結構出るな...)
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1896
85
3789aef7331d minor fix
kono
parents: 82
diff changeset
1897 あと、fpp のスタックに頼っているので、overflowした時に
3789aef7331d minor fix
kono
parents: 82
diff changeset
1898 困らないか? ほとんどの場合でだいじょうぶだが、だめだった
3789aef7331d minor fix
kono
parents: 82
diff changeset
1899 時にerrorぐらい出せば? でも実行時にしかわからないか...
3789aef7331d minor fix
kono
parents: 82
diff changeset
1900
3789aef7331d minor fix
kono
parents: 82
diff changeset
1901 I2D でさ、singned/unsigned の区別がいるね。
3789aef7331d minor fix
kono
parents: 82
diff changeset
1902
3789aef7331d minor fix
kono
parents: 82
diff changeset
1903 やっぱり FCONST いるんじゃないの?
87
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1904
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1905 Wed Mar 5 19:51:59 JST 2003
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1906
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1907 副作用以外は終ったけど.... あと、name space が結構重なっている
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1908 んだよね。
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1909 struct tag, struct field
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1910 が重なっているのは結構うっとうしい。gsearc/lsearch のあたりも
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1911 書き直さないとだめかも。
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1912
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1913 あと、list もなぁ。mode の作り方にもよるんでしょうけど。
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1914
1738f313f98b floating point (at most) done.
kono
parents: 85
diff changeset
1915 あと、結構、汚いよな...
88
5c8553d7f984 *** empty log message ***
kono
parents: 87
diff changeset
1916
5c8553d7f984 *** empty log message ***
kono
parents: 87
diff changeset
1917 Wed Mar 5 21:15:34 JST 2003
5c8553d7f984 *** empty log message ***
kono
parents: 87
diff changeset
1918
5c8553d7f984 *** empty log message ***
kono
parents: 87
diff changeset
1919 できたよ。まだ、テストしてない部分はあるけど。局所変数の初期化とか。
5c8553d7f984 *** empty log message ***
kono
parents: 87
diff changeset
1920 FCONST とか。3日で出来たね。
5c8553d7f984 *** empty log message ***
kono
parents: 87
diff changeset
1921
5c8553d7f984 *** empty log message ***
kono
parents: 87
diff changeset
1922 (gcc の方をやった方がいいかなぁ...)
89
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1923 goto.c が通らなくなってるな。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1924
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1925 Thu Mar 6 14:00:13 JST 2003
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1926
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1927 PowerPCのnon-lazy pointerって、テーブルに入っていてそれを読
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1928 み込む形式なのね。いったん、レジスタに読み込んだら、それを再
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1929 利用する形が良いらしい。ということは、code_gvar にキャッシュ
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1930 を作らないといけない。しかも RLU ですか? (めんどくさ〜)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1931 でも、そうしないと、
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1932 i = i+1;
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1933 なんてのでも、ひどい目にあってしまう。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1934
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1935 local variable も最初に move mutilple register で大半は
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1936 レジスタに読み込んじゃうみたいね。pointer で参照されると
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1937 困るんでしょうけど。まぁ、31個もあれば、そういうことを
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1938 してもあまり問題ないのかも知れないけど。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1939
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1940 creg を破壊しない実装にすれば、少しはましになるんじゃない?
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1941 (IA32では、それは難しいけど)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1942
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1943 Thu Mar 6 20:50:24 JST 2003
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1944
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1945 やっぱり、使った分だけregisterを保存するようなコードに
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1946 なるみたい。one path で、それをするためには、
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1947 .align 2
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1948 _main0__:
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1949 lwz r5,2136(r1)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1950 addi r1,r1,2128
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1951 lmw r23,-36(r1)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1952 mtlr r5
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1953 blr
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1954 .align 2
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1955 .globl _main0
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1956 _main0:
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1957 mflr r2
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1958 stmw r30,-8(r1)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1959 stw r2,8(r1)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1960 li r11,0
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1961 stwu r1,-480(r1)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1962 li r2,100
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1963 mtctr r2
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1964 mr r30,r3
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1965 addi r0,r1,64
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1966 mr r9,r0
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1967 b _main0__;
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1968 とかいう感じにするしかないね。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1969
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1970 あと引数は、レジスタに積むようになっているみたいだけど... r3 から?
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1971
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1972 mflr r31
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1973 li r0,7
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1974 stw r0,56(r1)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1975
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1976 だから8個まではレジスタに積むみたいね。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1977 r3-r10 だね。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1978
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1979 構造体もregisterにコピーされるのか。そして、向う側で受取の
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1980 コピーを行うわけだね。先頭にreturn structへのポインタがあるのも
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1981 同じ。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1982
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1983 (うう、memcpyしまくりだ...)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1984
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1985 浮動小数点もレジスタ渡し見たい。f1から。(なるほど)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1986
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1987 saveFPってのを呼び出して、 f24-f31をsaveするらしい。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1988 (31-24)*8 数合わないな?
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1989
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1990 pointer のことを考えると、レジスタだとまずいものもある
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1991 わけだけど。アドレスを取られてからで間に合うんじゃない?
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1992 配列などは、もともとだめだし。場所と値(?)は確保するとして。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1993
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1994 そうか、逆に、r3-r10 は引数でなければ壊しても良いわけか。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1995 (それでr9とか良く使われているわけか...)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1996 ということは足りなくなったら、引数をセーブすれば良いわけね。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1997 (ってことは、LVAR かつ REGISTER っていう状況があるんじゃん...
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1998 まぁ、そうだけどさ...)
917947ffeb7c power pc version
kono
parents: 88
diff changeset
1999 これは get_register がめんどくさそ。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2000
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2001 どうも、r11-r12 あたりは自由に使っているらしい。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2002
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2003 引数を作っている途中で関数呼出しするときは、どうするの?
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2004 r30などに移動するのか?
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2005
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2006 なんか知らんけど、in file call name と out file call name が
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2007 違うみたいね。(sigh...) こんなのなんとかなるのかなぁ。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2008 全部、stub にしておいて、.set で書き換えるという手もあるけど。
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2009
917947ffeb7c power pc version
kono
parents: 88
diff changeset
2010 (さすがに一日ではできないか...)
90
07e3113c3c13 *** empty log message ***
kono
parents: 89
diff changeset
2011
07e3113c3c13 *** empty log message ***
kono
parents: 89
diff changeset
2012 なんか整数から浮動小数点への変換はじぶんでやらないとだめなのね。
92
e7f8515ba882 *** empty log message ***
kono
parents: 90
diff changeset
2013 これはサブルーチンを呼んだ方がましだ。
e7f8515ba882 *** empty log message ***
kono
parents: 90
diff changeset
2014
e7f8515ba882 *** empty log message ***
kono
parents: 90
diff changeset
2015 get_register は絶対失敗しないようにできるんじゃないか?
e7f8515ba882 *** empty log message ***
kono
parents: 90
diff changeset
2016
e7f8515ba882 *** empty log message ***
kono
parents: 90
diff changeset
2017 label があると、code_base cache はclearしないといけない。
e7f8515ba882 *** empty log message ***
kono
parents: 90
diff changeset
2018 それを判断するには fwddef をhookする必要があるけど。
93
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2019
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2020 Fri Mar 7 09:17:10 JST 2003
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2021
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2022 問題は、
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2023 register allocation
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2024
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2025 function call/goto call
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2026 の構成だな。goto の方は machine dependentなところは
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2027 ほとんどない。register のsaveさえ必要ないから。
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2028
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2029 register allocation だけど。
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2030 r0
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2031 r1 frame pointer (or stack pointer )
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2032 r30 jj
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2033 r31 relocation register
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2034 r0,r1,r2 システムで使う
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2035 r0-r10 引数
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2036 引数でないところは優先的に使う
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2037 r20-r29 セーブして使う領域
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2038
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2039 r10-r19 はどうなんだろう? セーブしないのか?
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2040
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2041 ia32 の方でもfppのスタックを関数呼び出しのときに吐き出した方が
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2042 良い。
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2043
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2044 r0 r1 r2 r3 r4 r5 r6 r7 r8 r9
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2045 r10 r11 r12 r13 r14 r15 r16
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2046 r28 r29 r30 r31
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2047
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2048 なので、もののみごとに、17-27 までが使われてないね。
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2049
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2050 ということは、関す呼出し時には、保存されるレジスタはないと
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2051 思った方が良いってこと? あるいは、r17-r28 は保存されると
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2052 思って良いのかな。
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2053
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2054 Sat Mar 8 19:28:42 JST 2003
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2055
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2056 関数呼び出し時のレジスタセーブを避けるためには、関数呼び出し
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2057 を優先して実行してやれば良い。関数呼び出しの結果は局所変数に
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2058 セーブする。
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2059 f(g(h(a)+1)+2)
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2060 は、
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2061 a1=h(a)
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2062 a2=g(a1+1)
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2063 f(a1+2)
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2064 となる。そうすれば、関数呼び出しのときのスタックはかならず0になる。
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2065
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2066 でも、結局、引数は関数呼び出しの前にセーブするのね。だったら、
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2067 そんなことしないで、セーブすれば良いのか。
8f5d61239b93 *** empty log message ***
kono
parents: 92
diff changeset
2068
94
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2069 Mon Mar 10 11:42:40 JST 2003
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2070
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2071 で、レジスタのセーブなんだけど、mc-codegen.c を変更しない
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2072 とすれば、引数のリストを使って変更していくのが良い。
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2073 関数呼び出しは基本的には並列代入になる。並列代入でき
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2074 てもできなくても、セーブする必要はある。今の並列代入
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2075 ルーチンのできは良くないので、「同じかどうか」だけ
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2076 判断するのが良いのではないか?
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2077
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2078 関数呼び出しの前に式用にレジスタに積まれた値はセーブした
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2079 方が良い。セーブした後はlvarとしてアクセスすることになる。
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2080 スタックでもいいけど。
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2081 そうすると、stack 配列には、
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2082
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2083 レジスタ レジスタ番号 (>0)
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2084 スタック -1
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2085 lvar lvar番号
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2086
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2087 の三種類が入ることになる。それに合わせてtosop/assopを書き直
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2088 す必要がある。emit_pop だけでいいかも。スタックを止めちまう
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2089 のも手ではあるが、ia32の方で効率が悪い。やっぱり三種類サポー
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2090 トするのが良いだろう。
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2091
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2092 (けっこういろいろあるなぁ... どこから手を付けるか...)
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2093
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2094 Tue Mar 11 14:23:57 JST 2003
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2095
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2096 save_stacks すると、レジスタはほとんど使われなくなって
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2097 しまう。が、コードの見通しは良くなる。
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2098
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2099 定数を右辺に持って行くとsave_stacksでsaveする量が減る。が以
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2100 外にめんどくさいね。反射律が成り立たない演算子に関しては。tosop
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2101 の定数版とか作ることになるので... あとスタックに積む順序が逆
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2102 になってしまう。まぁ、もとの版では行われていたことだが...
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2103 CMPではrexpr で反転して論理を逆転させる方が簡単か。SUBでは、
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2104 ADD + (-CONST) にする方が良いね。
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2105
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2106 je _xxx
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2107 したあと、current register のregv[]が残ってしまう。これは、
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2108 変だよね。gexpr_init で regv が残るのは、case 文の比較だけ。
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2109 あとは全部0にして良い。(まぁ、害は無いんだけど)
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2110
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2111 (case 文のjumpは、switch 文が終る時に処理すれば、index jump
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2112 にすることができるね)
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2113
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2114 Wed Mar 12 12:58:47 JST 2003
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2115
1ad7045741a7 float dbinop fix
kono
parents: 93
diff changeset
2116 比較で入れ換えるとの否定は若干違うよね。
96
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2117
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2118 Thu Mar 13 19:39:48 JST 2003
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2119
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2120 そういえば、doif で条件が定数だったときとかの最適化は
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2121 してないんだね。やさしいけど。chk を使えば良いので。
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2122
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2123 f(g(1,2,3),g(1,2,3),g(1,2,3))
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2124
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2125 とかだと、結局、g の返り値は一旦メモリに入れないとだめじゃん。
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2126 なんだけど、実際は、r29-r22 を使っているようですね。
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2127
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2128 ってことは、function call の時に、r3-r10 が前の引数かどうかを
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2129 チェックして、引数だったらr29-r22に移す作業がいるわけだよね。
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2130 いったんr3とかに入れてしまった後だと、重複してしまうが...
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2131 前もって関数呼出しがあるかどうかは、調べることができるから、
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2132 関数呼び出しがあったら、そうするようにする?
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2133
7d8de41390d8 *** empty log message ***
kono
parents: 94
diff changeset
2134 いろいろめんどくさいなぁ... (いったい、いつなったらできるんだ?)
98
07c2554e1cfa *** empty log message ***
kono
parents: 96
diff changeset
2135
07c2554e1cfa *** empty log message ***
kono
parents: 96
diff changeset
2136 Fri Mar 14 10:38:25 JST 2003
07c2554e1cfa *** empty log message ***
kono
parents: 96
diff changeset
2137
07c2554e1cfa *** empty log message ***
kono
parents: 96
diff changeset
2138 function の dsp が、arglist と extern flag の両方を入れてしまっている。
07c2554e1cfa *** empty log message ***
kono
parents: 96
diff changeset
2139 本来は sc で区別するべき物だよね。
07c2554e1cfa *** empty log message ***
kono
parents: 96
diff changeset
2140
07c2554e1cfa *** empty log message ***
kono
parents: 96
diff changeset
2141 なんか、emit_pop_free のxregがLVARの時のバグを取るのに苦労した...
07c2554e1cfa *** empty log message ***
kono
parents: 96
diff changeset
2142 gdb は top level でのwhile を受け付けなくて、define してやなんないと
07c2554e1cfa *** empty log message ***
kono
parents: 96
diff changeset
2143 だめみたいね。
99
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2144
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2145 Fri Mar 14 15:50:28 JST 2003
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2146
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2147 なぁ... 書いても書いても書いても、終らん!
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2148
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2149 Fri Mar 14 19:43:44 JST 2003
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2150
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2151 jump の中で input register を割り振るときに floating point register の
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2152 ことを考えてなかった。これは register_var とは異なるので異なる
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2153 仕組みで割り振る必要がある。ってことは、get_input_register_var
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2154 が要るってこと?
53899975154c *** empty log message ***
kono
parents: 98
diff changeset
2155