-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler.cpp
More file actions
341 lines (282 loc) · 19.5 KB
/
Copy pathcompiler.cpp
File metadata and controls
341 lines (282 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#include "compiler.h"
#include "ast_etc.h"
#include "statement.h"
#include "type.h"
#include "expression.h"
#include "builtinfunctions.h"
#include <typeinfo>
#include <memory>
void Compiler::RegisterBuiltinFunction(string name,void (*funcptr)(shared_ptr<Flame>),shared_ptr<vector< pair<string,shared_ptr<TypeAST> > > > arg,shared_ptr<TypeAST> rettype,bool ctfeable){
genInfo->TopLevelFunction.push_back(make_shared<FunctionAST>(genInfo,name,arg,rettype,ctfeable));
VM::BuiltinFunctionList[pair<string,string>(name,genInfo->TopLevelFunction.back()->TypeInfo->GetName())]=funcptr;
}
void Compiler::ASTgen()
{
//演算子の準備
genInfo->OperatorList.insert(pair<string,OperatorInfo >("+",OperatorInfo(Binary,Left,20)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("-",OperatorInfo(Binary,Left,20)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("*",OperatorInfo(Binary,Left,40)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("/",OperatorInfo(Binary,Left,40)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("<<",OperatorInfo(Binary,Left,10)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >(">>",OperatorInfo(Binary,Left,10)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("%",OperatorInfo(Binary,Left,40)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("&&",OperatorInfo(Binary,Left,5)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("||",OperatorInfo(Binary,Left,5)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("!",OperatorInfo(Unary,Right,70)));
genInfo->OperatorList.insert(pair<string, OperatorInfo >("!", OperatorInfo(Binary, Right, 2)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("?",OperatorInfo(Unary,Right,70)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("-",OperatorInfo(Unary,Right,70)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("~",OperatorInfo(Unary,Right,70))); //単項マイナスの代替
genInfo->OperatorList.insert(pair<string, OperatorInfo >("@+", OperatorInfo(Binary, Left, 20)));
genInfo->OperatorList.insert(pair<string, OperatorInfo >("@?", OperatorInfo(Unary, Right, 70)));
genInfo->OperatorList.insert(pair<string, OperatorInfo >("@>", OperatorInfo(Unary, Right, 70)));
genInfo->OperatorList.insert(pair<string, OperatorInfo >("@<", OperatorInfo(Unary, Right, 70)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >(">",OperatorInfo(Binary,Left,8)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >(">=",OperatorInfo(Binary,Left,8)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("<",OperatorInfo(Binary,Left,8)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("<=",OperatorInfo(Binary,Left,8)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("!=",OperatorInfo(Binary,Left,8)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("==",OperatorInfo(Binary,Left,8)));
genInfo->OperatorList.insert(pair<string,OperatorInfo >("=",OperatorInfo(Binary,Right,2)));
vector< pair<string,shared_ptr<TypeAST> > > arglist;
RegisterBuiltinFunction("rand",rand_int,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("int"),false);
RegisterBuiltinFunction("hardware_concurrency",hw_concurrency,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("int"),false);
#ifdef USE_GLUT
RegisterBuiltinFunction("glut_mainloop",glut_mainloop,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_clear",glut_clear,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_flush",glut_flush,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_begin_point",glut_begin_point,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_begin_line",glut_begin_line,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_begin_strip",glut_begin_strip,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_begin_lineloop",glut_begin_lineloop,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_begin_triangle",glut_begin_triangle,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_begin_quad",glut_begin_quad,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_begin_trianglefan",glut_begin_trianglefan,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_begin_polygon",glut_begin_polygon,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_end",glut_end,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_postredisp", glut_postredisp, make_shared<vector< pair<string, shared_ptr<TypeAST> > > >(arglist), make_shared<BasicTypeAST>("void"), false);
vector<shared_ptr<TypeAST> > voidarg;voidarg.push_back(make_shared<BasicTypeAST>("void"));
arglist.push_back(pair<string,shared_ptr<TypeAST> >("val",make_shared<FunctionTypeAST>(voidarg)));
RegisterBuiltinFunction("glut_setdisplayfunc",glut_setdispfunc,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
arglist.clear();
vector<shared_ptr<TypeAST> > intarg;
intarg.push_back(make_shared<BasicTypeAST>("int"));
intarg.push_back(make_shared<BasicTypeAST>("int"));
intarg.push_back(make_shared<BasicTypeAST>("int"));
intarg.push_back(make_shared<BasicTypeAST>("void"));
arglist.push_back(pair<string,shared_ptr<TypeAST> >("val",make_shared<FunctionTypeAST>(intarg)));
RegisterBuiltinFunction("glut_setkeyboardfunc",glut_setkeyboardfunc,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
arglist.clear();
intarg.clear();
intarg.push_back(make_shared<BasicTypeAST>("int"));
intarg.push_back(make_shared<BasicTypeAST>("int"));
intarg.push_back(make_shared<BasicTypeAST>("int"));
intarg.push_back(make_shared<BasicTypeAST>("int"));
intarg.push_back(make_shared<BasicTypeAST>("void"));
arglist.push_back(pair<string,shared_ptr<TypeAST> >("val",make_shared<FunctionTypeAST>(intarg)));
RegisterBuiltinFunction("glut_setmousefunc",glut_setmousefunc,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
arglist.clear();
intarg.clear();
intarg.push_back(make_shared<BasicTypeAST>("int"));
intarg.push_back(make_shared<BasicTypeAST>("void"));
arglist.push_back(pair<string,shared_ptr<TypeAST> >("msec",make_shared<BasicTypeAST>("int")));
arglist.push_back(pair<string,shared_ptr<TypeAST> >("callback",make_shared<FunctionTypeAST>(intarg)));
arglist.push_back(pair<string,shared_ptr<TypeAST> >("value",make_shared<BasicTypeAST>("int")));
RegisterBuiltinFunction("glut_settimerfunc",glut_settimerfunc,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
arglist.clear();
#endif
arglist.clear();
arglist.push_back(pair<string,shared_ptr<TypeAST> >("val",make_shared<BasicTypeAST>("int")));
RegisterBuiltinFunction("print_int",print_int,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("sleep",sleep_msec,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
arglist[0]=pair<string,shared_ptr<TypeAST> >("val",make_shared<BasicTypeAST>("double"));
RegisterBuiltinFunction("print_double",print_double,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
arglist[0]=pair<string,shared_ptr<TypeAST> >("val",make_shared<BasicTypeAST>("bool"));
RegisterBuiltinFunction("print_bool",print_bool,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
arglist[0]=pair<string,shared_ptr<TypeAST> >("str",make_shared<BasicTypeAST>("string"));
RegisterBuiltinFunction("print",print_str,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
#ifdef USE_GLUT
RegisterBuiltinFunction("glut_openwindow",glut_openwindow,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
#endif
arglist[0]=pair<string,shared_ptr<TypeAST> >("val",make_shared<BasicTypeAST>("int"));
RegisterBuiltinFunction("abs",abs_int,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("int"),true);
arglist[0]=pair<string,shared_ptr<TypeAST> >("val",make_shared<BasicTypeAST>("int"));
RegisterBuiltinFunction("i2d",int2double,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("double"),true);
arglist[0]=pair<string,shared_ptr<TypeAST> >("val",make_shared<BasicTypeAST>("double"));
RegisterBuiltinFunction("d2i",double2int,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("int"),true);
RegisterBuiltinFunction("sin",math_sin,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("double"),true);
RegisterBuiltinFunction("cos",math_cos,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("double"),true);
RegisterBuiltinFunction("tan",math_tan,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("double"),true);
RegisterBuiltinFunction("asin",math_asin,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("double"),true);
RegisterBuiltinFunction("acos",math_acos,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("double"),true);
RegisterBuiltinFunction("atan",math_atan,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("double"),true);
RegisterBuiltinFunction("sqrt",math_sqrt,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("double"),true);
arglist[0]=pair<string,shared_ptr<TypeAST> >("val1",make_shared<BasicTypeAST>("int"));
arglist.push_back(pair<string,shared_ptr<TypeAST> >("val2",make_shared<BasicTypeAST>("int")));
RegisterBuiltinFunction("pow",pow_int,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("int"),true);
#ifdef USE_GLUT
RegisterBuiltinFunction("glut_vertex2i",glut_vertex2i,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
arglist.push_back(pair<string,shared_ptr<TypeAST> >("val3",make_shared<BasicTypeAST>("int")));
RegisterBuiltinFunction("glut_color3i",glut_color3i,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
RegisterBuiltinFunction("glut_char",glut_char,make_shared<vector< pair<string,shared_ptr<TypeAST> > > >(arglist),make_shared<BasicTypeAST>("void"),false);
#endif
//演算子から関数呼び出しへの橋渡し(引数などの情報は無視される)
RegisterBuiltinFunction("!op_append_list", op_append_list, make_shared<vector< pair<string, shared_ptr<TypeAST> > > >(), make_shared<BasicTypeAST>("<...>"), true);
RegisterBuiltinFunction("!op_append_str", op_append_str, make_shared<vector< pair<string, shared_ptr<TypeAST> > > >(), make_shared<BasicTypeAST>("<...>"), true);
RegisterBuiltinFunction("!op_cdr", op_cdr, make_shared<vector< pair<string, shared_ptr<TypeAST> > > >(), make_shared<BasicTypeAST>("<...>"), true);
RegisterBuiltinFunction("!op_car", op_car, make_shared<vector< pair<string, shared_ptr<TypeAST> > > >(), make_shared<BasicTypeAST>("<...>"), true);
RegisterBuiltinFunction("!op_cons", op_cons, make_shared<vector< pair<string, shared_ptr<TypeAST> > > >(), make_shared<BasicTypeAST>("<...>"), true);
RegisterBuiltinFunction("!op_length_list", op_length_list, make_shared<vector< pair<string, shared_ptr<TypeAST> > > >(), make_shared<BasicTypeAST>("<...>"), true);
RegisterBuiltinFunction("!op_length_vector", op_length_vector, make_shared<vector< pair<string, shared_ptr<TypeAST> > > >(), make_shared<BasicTypeAST>("<...>"), true);
RegisterBuiltinFunction("!op_length_str", op_length_str, make_shared<vector< pair<string, shared_ptr<TypeAST> > > >(), make_shared<BasicTypeAST>("<...>"), true);
while(!parser->IsAccepted()){
pair<Symbol,TokenValue> token=lexer->Get();
//cout <<"token: "<<Parser::Symbol2Str(token.first)<<endl;
parser->Put(lexer,genInfo,token);
}
}
void Compiler::TypeCheck()
{
shared_ptr<vector<Environment> > environment=make_shared<vector<Environment> >(); //現在可視状態にある変数(トップレベルの関数も変数とみなす)のスタック(フレームを積み重ねていく)
vector<shared_ptr<FunctionAST> >::iterator fun_iter;
vector<shared_ptr<VariableDefStatementAST> >::iterator var_iter;
Environment rootflame;
rootflame.is_internalblock=false;
rootflame.LocalVariablesPtr=genInfo->LocalVariables;
int cnt=0;
for(fun_iter=genInfo->TopLevelFunction.begin();fun_iter!=genInfo->TopLevelFunction.end();fun_iter++){
EnvItem ei;ei.VariableInfo=pair<string,shared_ptr<TypeAST> >((*fun_iter)->Name,(*fun_iter)->TypeInfo);ei.LocalIndex=cnt;
rootflame.Items.push_back(ei);
cnt++;
}
for(var_iter=genInfo->TopLevelVariableDef.begin();var_iter!=genInfo->TopLevelVariableDef.end();var_iter++){
EnvItem ei;ei.VariableInfo=*((*var_iter)->Variable);ei.LocalIndex=cnt;
rootflame.Items.push_back(ei);
cnt++;
}
environment->push_back(rootflame); //トップレベルのフレーム
for(fun_iter=genInfo->TopLevelFunction.begin();fun_iter!=genInfo->TopLevelFunction.end();fun_iter++){
if((*fun_iter)->isBuiltin==false){
(*fun_iter)->CheckType(environment,genInfo,genInfo->LocalVariables);
}
rootflame.LocalVariablesPtr->push_back(pair<string,shared_ptr<TypeAST> >((*fun_iter)->Name,(*fun_iter)->TypeInfo));
}
for(var_iter=genInfo->TopLevelVariableDef.begin();var_iter!=genInfo->TopLevelVariableDef.end();var_iter++){
(*var_iter)->CheckType(environment,genInfo,genInfo->LocalVariables);
//rootflame.LocalVariablesPtr->push_back(*((*var_iter)->Variable));
}
}
void Compiler::Codegen()
{
vector<shared_ptr<FunctionAST> >::iterator iterf;
vector<shared_ptr<VariableDefStatementAST> >::iterator iterv;
for(iterf=genInfo->TopLevelFunction.begin();iterf!=genInfo->TopLevelFunction.end();iterf++){
//組み込み関数のコード生成は行わない
if((*iterf)->isBuiltin==false){
(*iterf)->Codegen(nullptr,genInfo);
}
}
//main関数(引数なしで、戻り値がvoidであるもの)を探す
int main_index=-1;
for(iterf=genInfo->TopLevelFunction.begin();iterf!=genInfo->TopLevelFunction.end();iterf++){
if((*iterf)->Name=="main" && (*iterf)->TypeInfo->GetName()=="fun()=>void"){
main_index=(*iterf)->PoolIndex;
}
}
if(main_index==-1){
error("適切なmain関数が見つかりません。");
}
genInfo->MainFuncPoolIndex=main_index;
genInfo->Bootstrap->clear();
//ブートストラップローダをつくる
//トップレベルの関数の初期化
int counter=0;
for(iterf=genInfo->TopLevelFunction.begin();iterf!=genInfo->TopLevelFunction.end();iterf++){
//トップレベル関数はもうコード生成が済んでいるのでCodegenはダメ
genInfo->Bootstrap->push_back(makeclosure);
genInfo->Bootstrap->push_back((*iterf)->PoolIndex);
genInfo->Bootstrap->push_back(storelocal);
genInfo->Bootstrap->push_back(0);
genInfo->Bootstrap->push_back(counter++);
}
genInfo->Bootstrap->push_back(clean);
//グローバル変数の初期化
for(iterv=genInfo->TopLevelVariableDef.begin();iterv!=genInfo->TopLevelVariableDef.end();iterv++){
(*iterv)->Codegen(genInfo->Bootstrap,genInfo);
genInfo->Bootstrap->push_back(clean);
}
//main関数の呼び出し
genInfo->Bootstrap->push_back(makeclosure);
genInfo->Bootstrap->push_back(genInfo->MainFuncPoolIndex);
genInfo->Bootstrap->push_back(invoke);
genInfo->Bootstrap->push_back(ret);
VM::BytecodeToLabels(genInfo->Bootstrap,genInfo->Bootstrap_labels);
}
void Compiler::CTFE(int loop/*繰り返し回数*/){
/*vector<shared_ptr<ExprAST> > call_list;
vector< shared_ptr<CallExprAST> > exec_list;
vector<shared_ptr<ExprAST> > temp;
vector<shared_ptr<FunctionAST> >::iterator iterf;
vector<shared_ptr<ExprAST> >::iterator citer;
vector<shared_ptr<CallExprAST> >::iterator iter;
int exec_count=0;
for(int i=0;i<loop;i++){
call_list.clear();
exec_list.clear();
for(iterf=genInfo->TopLevelFunction.begin();iterf!=genInfo->TopLevelFunction.end();iterf++){
if(!(*iterf)->isBuiltin){
temp=(*iterf)->GetCallExprList();
call_list.insert(call_list.end(),temp.begin(),temp.end());
}
}
for(citer=call_list.begin();citer!=call_list.end();citer++){
shared_ptr<CallExprAST> target=dynamic_pointer_cast<CallExprAST>(*citer);
if(typeid(VariableExprAST)==typeid(*(target->callee))){
if(dynamic_pointer_cast<VariableExprAST >(target->callee)->is_toplevel_func && genInfo->TopLevelFunction[dynamic_pointer_cast<VariableExprAST >(target->callee)->LocalIndex]->IsCTFEable(genInfo,-1)){
vector<shared_ptr<ExprAST> >::iterator aiter;
for(aiter=target->args->begin();aiter!=target->args->end();aiter++){
if((*aiter)->IsCTFEable(genInfo,-1)==false || (*aiter)->IsConstant()==false){
goto next_c;
}
}
//事前計算対象に選ばれた
exec_list.push_back(target);
}
}
next_c:
1+1;//dummy expression
}
if(exec_list.size()==0){
break;
}
vector<int> preexec_code; //事前実行する関数呼び出しをズラッと並べたもの
for(iter=exec_list.begin();iter!=exec_list.end();iter++){
exec_count++;
if((*iter)->TypeInfo->GetName()=="void"){
VMValue v;v.primitive.int_value=0;
(*iter)->CalculatedValue=v;
continue;
}
preexec_code.clear();
//トップレベルの関数(組み込み関数も含める)のCodegenInfo.ToplevelFuncList
//のインデックスとLocalIndexは一致すると仮定している(closureがはいってる)
for(vector<shared_ptr<ExprAST> >::reverse_iterator eiter=(*iter)->args->rbegin();eiter!=(*iter)->args->rend();eiter++){
preexec_code.push_back(ipush);
preexec_code.push_back((*eiter)->GetVMValue(genInfo));
}
preexec_code.push_back(iloadlocal);
preexec_code.push_back(0); //FlameBack
preexec_code.push_back(dynamic_cast<Variableshared_ptr<ExprAST> >((*iter)->callee)->LocalIndex);
preexec_code.push_back(invoke);
preexec_code.push_back(ret);
genInfo->Bootstrap=preexec_code;
VM vm(genInfo);
vm.Init();
(*iter)->callee=nullptr;
(*iter)->CalculatedValue=vm.Run(false);
}
Codegen();
}
cout<<exec_count<<"箇所の関数呼び出しを事前実行しました"<<endl;
return;*/
}