1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | #include <jenga/include/smoothie/LexicalAnalysis.h>
|
---|
4 |
|
---|
5 | #include <LexicalScope.h>
|
---|
6 | #include <Compiler.h>
|
---|
7 |
|
---|
8 | #include "../BasicCompiler_Common/common.h"
|
---|
9 | #include "Opcode.h"
|
---|
10 |
|
---|
11 | void OpcodeOthers( const char *Command ){
|
---|
12 | int i,i2;
|
---|
13 |
|
---|
14 | char leftTerm[8192];
|
---|
15 | int lastParePos = 0;
|
---|
16 | for(i=0;;i++){
|
---|
17 | if(Command[i]=='\"'){
|
---|
18 | //ダブルクォートは不正なのでエラー扱い
|
---|
19 | leftTerm[i]=0;
|
---|
20 | SetError(3,leftTerm,cp);
|
---|
21 | return;
|
---|
22 | }
|
---|
23 |
|
---|
24 | if(Command[i]=='('){
|
---|
25 | lastParePos = i;
|
---|
26 | i2=GetStringInPare(leftTerm+i,Command+i);
|
---|
27 | i+=i2-1;
|
---|
28 | continue;
|
---|
29 | }
|
---|
30 | if(Command[i]=='['){
|
---|
31 | i2=GetStringInBracket(leftTerm+i,Command+i);
|
---|
32 | i+=i2-1;
|
---|
33 | continue;
|
---|
34 | }
|
---|
35 | if(Command[i]=='\0'){
|
---|
36 | leftTerm[i] = 0;
|
---|
37 | break;
|
---|
38 | }
|
---|
39 |
|
---|
40 | if( IsNumCalcMark( Command, i ) ){
|
---|
41 | leftTerm[i] = 0;
|
---|
42 | break;
|
---|
43 | }
|
---|
44 |
|
---|
45 | leftTerm[i]=Command[i];
|
---|
46 | }
|
---|
47 | if(!(
|
---|
48 | IsVariableTopChar(leftTerm[0])||
|
---|
49 | leftTerm[0]=='.'||
|
---|
50 | (leftTerm[0]==1&&leftTerm[1]==ESC_PSMEM)
|
---|
51 | )){
|
---|
52 | SetError(1,NULL,cp);
|
---|
53 | return;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | if(Command[i]=='\0' && lastParePos == 0){
|
---|
58 | //////////////////////////////
|
---|
59 | // パラメータ無しのマクロ検索
|
---|
60 | //////////////////////////////
|
---|
61 |
|
---|
62 | const UserProc *pUserProc = GetSubHash(Command);
|
---|
63 |
|
---|
64 | //GetSubHash内でエラー提示が行われた場合
|
---|
65 | if(pUserProc==(UserProc *)-1) return;
|
---|
66 |
|
---|
67 | if(pUserProc==0){
|
---|
68 | char temporary[VN_SIZE];
|
---|
69 | lstrcpy(temporary,Command);
|
---|
70 |
|
---|
71 | CharUpper(temporary);
|
---|
72 | pUserProc=GetSubHash(temporary);
|
---|
73 |
|
---|
74 | //GetSubHash内でエラー提示が行われた場合
|
---|
75 | if(pUserProc==(UserProc *)-1) return;
|
---|
76 | }
|
---|
77 |
|
---|
78 | if(pUserProc){
|
---|
79 | if( !pUserProc->IsMacro() ){
|
---|
80 | SetError(10,Command,cp);
|
---|
81 | }
|
---|
82 |
|
---|
83 | Opcode_CallProc("",pUserProc,0,"");
|
---|
84 |
|
---|
85 | return;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | else if(IsNumCalcMark(Command,i)){
|
---|
89 | //代入演算
|
---|
90 | OpcodeCalc(Command);
|
---|
91 | return;
|
---|
92 | }
|
---|
93 |
|
---|
94 | Type resultType;
|
---|
95 | bool isLiteral;
|
---|
96 | BOOL bUseHeap;
|
---|
97 | bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, &bUseHeap, false, NULL, true );
|
---|
98 | if( result ){
|
---|
99 |
|
---|
100 | /////////////////////
|
---|
101 | // 戻り値の処理
|
---|
102 | /////////////////////
|
---|
103 |
|
---|
104 | if( resultType.IsReal() ){
|
---|
105 | //fstp st(0)
|
---|
106 | compiler.codeGenerator.PutOld(
|
---|
107 | (char)0xDD,
|
---|
108 | (char)0xD8
|
---|
109 | );
|
---|
110 | }
|
---|
111 | else if( resultType.IsStruct() ){
|
---|
112 | //mov ebx,eax
|
---|
113 | compiler.codeGenerator.op_mov_RR(REG_EBX,REG_EAX);
|
---|
114 |
|
---|
115 | FreeTempObject(REG_EBX,&resultType.GetClass());
|
---|
116 | }
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | void OpcodeIf(char *Parameter){
|
---|
121 | int i,i2;
|
---|
122 | Type tempType;
|
---|
123 |
|
---|
124 | for(i=0;;i++){
|
---|
125 | if(Parameter[i]=='\0'){
|
---|
126 | SetError(21,NULL,cp);
|
---|
127 | return;
|
---|
128 | }
|
---|
129 | if(Parameter[i]==1&&Parameter[i+1]==ESC_THEN){
|
---|
130 | Parameter[i]=0;
|
---|
131 | break;
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | const PertialSchedule *pIfPertialSchedule = NULL;
|
---|
136 | if( !NumOpe(Parameter,Type(DEF_BOOLEAN),tempType) ){
|
---|
137 | //NumOpe内でエラー
|
---|
138 | }
|
---|
139 | else if( tempType.IsDouble() ){
|
---|
140 | //fld qword ptr[esp]
|
---|
141 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
---|
142 |
|
---|
143 | //push 0
|
---|
144 | compiler.codeGenerator.op_push_V(0);
|
---|
145 |
|
---|
146 | //fild dword ptr[esp]
|
---|
147 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
---|
148 |
|
---|
149 | //add esp,sizeof(double)+sizeof(long)
|
---|
150 | compiler.codeGenerator.op_add_esp(sizeof(double)+sizeof(long));
|
---|
151 |
|
---|
152 | //fcompp
|
---|
153 | compiler.codeGenerator.op_fcompp();
|
---|
154 |
|
---|
155 | //fnstsw ax
|
---|
156 | compiler.codeGenerator.op_fnstsw_ax();
|
---|
157 |
|
---|
158 | //test ah,40
|
---|
159 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
---|
160 |
|
---|
161 | //jne (endif、または else まで)
|
---|
162 | pIfPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true );
|
---|
163 | }
|
---|
164 | else if( tempType.IsSingle() ){
|
---|
165 | //fld dword ptr[esp]
|
---|
166 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
---|
167 |
|
---|
168 | //push 0
|
---|
169 | compiler.codeGenerator.op_push_V(0);
|
---|
170 |
|
---|
171 | //fild dword ptr[esp]
|
---|
172 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
---|
173 |
|
---|
174 | //add esp,sizeof(float)+sizeof(long)
|
---|
175 | compiler.codeGenerator.op_add_esp(sizeof(float)+sizeof(long));
|
---|
176 |
|
---|
177 | //fcompp
|
---|
178 | compiler.codeGenerator.op_fcompp();
|
---|
179 |
|
---|
180 | //fnstsw ax
|
---|
181 | compiler.codeGenerator.op_fnstsw_ax();
|
---|
182 |
|
---|
183 | //test ah,40
|
---|
184 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
---|
185 |
|
---|
186 | //jne (endif、または else まで)
|
---|
187 | pIfPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true );
|
---|
188 | }
|
---|
189 | else if( tempType.Is64() ){
|
---|
190 | //64ビット型
|
---|
191 |
|
---|
192 | //pop eax
|
---|
193 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
194 |
|
---|
195 | //pop ebx
|
---|
196 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
197 |
|
---|
198 | //cmp eax,0
|
---|
199 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
---|
200 |
|
---|
201 | //jne
|
---|
202 | const PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
---|
203 |
|
---|
204 | //cmp ebx,0
|
---|
205 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EBX, 0 );
|
---|
206 |
|
---|
207 | //jne
|
---|
208 | const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
---|
209 |
|
---|
210 | //jmp (endif、または else までジャンプ)
|
---|
211 | pIfPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
---|
212 |
|
---|
213 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 );
|
---|
214 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 );
|
---|
215 | }
|
---|
216 | else{
|
---|
217 | //32ビット型
|
---|
218 |
|
---|
219 | //pop eax
|
---|
220 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
221 |
|
---|
222 | //cmp eax,0
|
---|
223 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
---|
224 |
|
---|
225 | //je (endif、または else まで条件ジャンプ)
|
---|
226 | pIfPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );
|
---|
227 | }
|
---|
228 |
|
---|
229 |
|
---|
230 | /////////////////////////
|
---|
231 | // If内をコード化
|
---|
232 | /////////////////////////
|
---|
233 |
|
---|
234 | //レキシカルスコープをレベルアップ
|
---|
235 | compiler.codeGenerator.lexicalScopes.Start(
|
---|
236 | compiler.codeGenerator.GetNativeCodeSize(),
|
---|
237 | LexicalScope::SCOPE_TYPE_IF
|
---|
238 | );
|
---|
239 |
|
---|
240 | i2=CompileBuffer(ESC_ENDIF,0);
|
---|
241 |
|
---|
242 | //レキシカルスコープをレベルダウン
|
---|
243 | compiler.codeGenerator.lexicalScopes.End();
|
---|
244 |
|
---|
245 |
|
---|
246 | if( pIfPertialSchedule == NULL ) return;
|
---|
247 |
|
---|
248 | if(i2==ESC_ELSE){
|
---|
249 | //jmp (endifまで)
|
---|
250 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
---|
251 |
|
---|
252 | compiler.codeGenerator.opfix_JmpPertialSchedule( pIfPertialSchedule );
|
---|
253 |
|
---|
254 |
|
---|
255 | /////////////////////////
|
---|
256 | // Else内をコード化
|
---|
257 | /////////////////////////
|
---|
258 |
|
---|
259 | //レキシカルスコープをレベルアップ
|
---|
260 | compiler.codeGenerator.lexicalScopes.Start(
|
---|
261 | compiler.codeGenerator.GetNativeCodeSize(),
|
---|
262 | LexicalScope::SCOPE_TYPE_IF
|
---|
263 | );
|
---|
264 |
|
---|
265 | CompileBuffer(ESC_ENDIF,0);
|
---|
266 |
|
---|
267 | //レキシカルスコープをレベルダウン
|
---|
268 | compiler.codeGenerator.lexicalScopes.End();
|
---|
269 |
|
---|
270 |
|
---|
271 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
272 | }
|
---|
273 | else{
|
---|
274 | compiler.codeGenerator.opfix_JmpPertialSchedule( pIfPertialSchedule );
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | int GetLabelAddress(char *LabelName,int LineNum){
|
---|
279 | if(LabelName){
|
---|
280 | BOOST_FOREACH( const GotoLabel &label, compiler.codeGenerator.gotoLabels )
|
---|
281 | {
|
---|
282 | if( label.name.size() > 0 )
|
---|
283 | {
|
---|
284 | if( label.name == LabelName )
|
---|
285 | {
|
---|
286 | return label.address;
|
---|
287 | }
|
---|
288 | }
|
---|
289 | }
|
---|
290 | }
|
---|
291 | else{
|
---|
292 | BOOST_FOREACH( const GotoLabel &label, compiler.codeGenerator.gotoLabels )
|
---|
293 | {
|
---|
294 | if( label.name.size() == 0 )
|
---|
295 | {
|
---|
296 | if( label.line == LineNum )
|
---|
297 | {
|
---|
298 | return label.address;
|
---|
299 | }
|
---|
300 | }
|
---|
301 | }
|
---|
302 | }
|
---|
303 | return -1;
|
---|
304 | }
|
---|
305 | void OpcodeGoto(char *Parameter){
|
---|
306 | extern HANDLE hHeap;
|
---|
307 | int i,LineNum;
|
---|
308 |
|
---|
309 | if(Parameter[0]=='*'){
|
---|
310 | i=GetLabelAddress(Parameter+1,0);
|
---|
311 |
|
---|
312 | if( i == -1 )
|
---|
313 | {
|
---|
314 | //jmp ...(schedule)
|
---|
315 | compiler.codeGenerator.op_jmp_goto_schedule( (const std::string)(Parameter + 1), 0, cp );
|
---|
316 | }
|
---|
317 | else
|
---|
318 | {
|
---|
319 | //jmp ...
|
---|
320 | compiler.codeGenerator.op_jmp(
|
---|
321 | i-compiler.codeGenerator.GetNativeCodeSize(),
|
---|
322 | sizeof(long),
|
---|
323 | false,
|
---|
324 | true
|
---|
325 | );
|
---|
326 | }
|
---|
327 | }
|
---|
328 | else{
|
---|
329 | LineNum=atoi(Parameter);
|
---|
330 | i=GetLabelAddress(0,LineNum);
|
---|
331 |
|
---|
332 | if( i == -1 )
|
---|
333 | {
|
---|
334 | //jmp ...(schedule)
|
---|
335 | compiler.codeGenerator.op_jmp_goto_schedule( "", LineNum, cp );
|
---|
336 | }
|
---|
337 | else
|
---|
338 | {
|
---|
339 | //jmp ...
|
---|
340 | compiler.codeGenerator.op_jmp(
|
---|
341 | i-compiler.codeGenerator.GetNativeCodeSize(),
|
---|
342 | sizeof(long),
|
---|
343 | false,
|
---|
344 | true
|
---|
345 | );
|
---|
346 | }
|
---|
347 | }
|
---|
348 | }
|
---|
349 | void OpcodeWhile(char *Parameter){
|
---|
350 | extern HANDLE hHeap;
|
---|
351 |
|
---|
352 | //Continueアドレスのバックアップとセット
|
---|
353 | compiler.codeGenerator.ContinueAreaBegin();
|
---|
354 |
|
---|
355 | if(!Parameter[0]) SetError(10,"While",cp);
|
---|
356 |
|
---|
357 | const PertialSchedule *pWhilePertialSchedule = NULL;
|
---|
358 | Type tempType;
|
---|
359 | if( !NumOpe(Parameter,Type(),tempType) ){
|
---|
360 | //ダミー
|
---|
361 | }
|
---|
362 | else if( tempType.IsDouble() ){
|
---|
363 | //fld qword ptr[esp]
|
---|
364 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
---|
365 |
|
---|
366 | //push 0
|
---|
367 | compiler.codeGenerator.op_push_V(0);
|
---|
368 |
|
---|
369 | //fild dword ptr[esp]
|
---|
370 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
---|
371 |
|
---|
372 | //add esp,sizeof(double)+sizeof(long)
|
---|
373 | compiler.codeGenerator.op_add_esp(sizeof(double)+sizeof(long));
|
---|
374 |
|
---|
375 | //fcompp
|
---|
376 | compiler.codeGenerator.op_fcompp();
|
---|
377 |
|
---|
378 | //fnstsw ax
|
---|
379 | compiler.codeGenerator.op_fnstsw_ax();
|
---|
380 |
|
---|
381 | //test ah,40
|
---|
382 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
---|
383 |
|
---|
384 | //jne (Wend まで)
|
---|
385 | pWhilePertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true );
|
---|
386 | }
|
---|
387 | else if( tempType.IsSingle() ){
|
---|
388 | //fld dword ptr[esp]
|
---|
389 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
---|
390 |
|
---|
391 | //push 0
|
---|
392 | compiler.codeGenerator.op_push_V(0);
|
---|
393 |
|
---|
394 | //fild dword ptr[esp]
|
---|
395 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
---|
396 |
|
---|
397 | //add esp,sizeof(float)+sizeof(long)
|
---|
398 | compiler.codeGenerator.op_add_esp(sizeof(float)+sizeof(long));
|
---|
399 |
|
---|
400 | //fcompp
|
---|
401 | compiler.codeGenerator.op_fcompp();
|
---|
402 |
|
---|
403 | //fnstsw ax
|
---|
404 | compiler.codeGenerator.op_fnstsw_ax();
|
---|
405 |
|
---|
406 | //test ah,40h
|
---|
407 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
---|
408 |
|
---|
409 | //jne (Wend まで)
|
---|
410 | pWhilePertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(long), true );
|
---|
411 | }
|
---|
412 | else if( tempType.Is64() ){
|
---|
413 | //64ビット型
|
---|
414 |
|
---|
415 | //pop eax
|
---|
416 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
417 |
|
---|
418 | //pop ebx
|
---|
419 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
420 |
|
---|
421 | //cmp eax,0
|
---|
422 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
---|
423 |
|
---|
424 | //jne
|
---|
425 | const PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
---|
426 |
|
---|
427 | //cmp ebx,0
|
---|
428 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EBX, 0 );
|
---|
429 |
|
---|
430 | //jne
|
---|
431 | const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
---|
432 |
|
---|
433 | //jmp (Wendまでジャンプ)
|
---|
434 | pWhilePertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
---|
435 |
|
---|
436 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 );
|
---|
437 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 );
|
---|
438 | }
|
---|
439 | else{
|
---|
440 | //その他整数型
|
---|
441 |
|
---|
442 | //pop eax
|
---|
443 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
444 |
|
---|
445 | //cmp eax,0
|
---|
446 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
---|
447 |
|
---|
448 | //je (Wend まで)
|
---|
449 | pWhilePertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );
|
---|
450 | }
|
---|
451 |
|
---|
452 | //レキシカルスコープをレベルアップ
|
---|
453 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_WHILE );
|
---|
454 |
|
---|
455 | //While内をコンパイル
|
---|
456 | CompileBuffer(0,COM_WEND);
|
---|
457 |
|
---|
458 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
---|
459 |
|
---|
460 | //jmp ...
|
---|
461 | compiler.codeGenerator.op_jmp_continue();
|
---|
462 |
|
---|
463 | //レキシカルスコープをレベルダウン
|
---|
464 | compiler.codeGenerator.lexicalScopes.End();
|
---|
465 |
|
---|
466 | if( pWhilePertialSchedule )
|
---|
467 | {
|
---|
468 | compiler.codeGenerator.opfix_JmpPertialSchedule( pWhilePertialSchedule );
|
---|
469 | }
|
---|
470 |
|
---|
471 | compiler.codeGenerator.ContinueAreaEnd();
|
---|
472 | }
|
---|
473 |
|
---|
474 | char szNextVariable[VN_SIZE];
|
---|
475 | void OpcodeFor(char *Parameter){
|
---|
476 | extern HANDLE hHeap;
|
---|
477 | int i,i2;
|
---|
478 | char temporary[VN_SIZE],variable[VN_SIZE],JudgeNum[VN_SIZE],StepNum[VN_SIZE];
|
---|
479 |
|
---|
480 | //第1パラメータを取得
|
---|
481 | i=GetOneParameter(Parameter,0,temporary);
|
---|
482 | if(!Parameter[i]){
|
---|
483 | SetError(12,"For",cp);
|
---|
484 | goto ErrorStep;
|
---|
485 | }
|
---|
486 |
|
---|
487 | for(i2=0;;i2++){
|
---|
488 | if(temporary[i2]=='='){
|
---|
489 | variable[i2]=0;
|
---|
490 |
|
---|
491 | //カウンタ初期化
|
---|
492 | OpcodeCalc(temporary);
|
---|
493 | break;
|
---|
494 | }
|
---|
495 | if(temporary[i2]=='\0'){
|
---|
496 | SetError(12,"For",cp);
|
---|
497 | goto ErrorStep;
|
---|
498 | }
|
---|
499 | variable[i2]=temporary[i2];
|
---|
500 | }
|
---|
501 |
|
---|
502 | //jmp ...
|
---|
503 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
---|
504 |
|
---|
505 | //Continueアドレスのバックアップとセット
|
---|
506 | compiler.codeGenerator.ContinueAreaBegin();
|
---|
507 |
|
---|
508 | //第2パラメータを取得(to~)
|
---|
509 | i=GetOneParameter(Parameter,i,JudgeNum);
|
---|
510 |
|
---|
511 | //第3パラメータを取得(step~)
|
---|
512 | if(Parameter[i]){
|
---|
513 | i=GetOneParameter(Parameter,i,StepNum);
|
---|
514 | if(Parameter[i]) SetError(12,"For",cp);
|
---|
515 | }
|
---|
516 | else lstrcpy(StepNum,"1");
|
---|
517 |
|
---|
518 | //カウンタを増加させる
|
---|
519 | sprintf(temporary,"%s=(%s)+(%s)",variable,variable,StepNum);
|
---|
520 | OpcodeCalc(temporary);
|
---|
521 |
|
---|
522 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
523 |
|
---|
524 | //増加か減少かを区別する
|
---|
525 | sprintf(temporary,"(%s)>=0",StepNum);
|
---|
526 | NumOpe(temporary,Type(),Type());
|
---|
527 |
|
---|
528 | //pop eax
|
---|
529 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
530 |
|
---|
531 | //cmp eax,0
|
---|
532 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
---|
533 |
|
---|
534 | //je [カウンタ減少の場合の判定]
|
---|
535 | pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );
|
---|
536 |
|
---|
537 | //判定(カウンタ増加の場合)
|
---|
538 | sprintf(temporary,"%s<=(%s)",variable,JudgeNum);
|
---|
539 | NumOpe(temporary,Type(),Type());
|
---|
540 |
|
---|
541 | //pop eax
|
---|
542 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
543 |
|
---|
544 | //jmp [カウンタ減少の場合の判定を飛び越す]
|
---|
545 | const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
---|
546 |
|
---|
547 | //jeジャンプ先のオフセット値
|
---|
548 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
549 |
|
---|
550 | //判定(カウンタ減少の場合)
|
---|
551 | sprintf(temporary,"%s>=(%s)",variable,JudgeNum);
|
---|
552 | NumOpe(temporary,Type(),Type());
|
---|
553 |
|
---|
554 | //pop eax
|
---|
555 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
556 |
|
---|
557 | //jmpジャンプ先のオフセット値
|
---|
558 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 );
|
---|
559 |
|
---|
560 | //cmp eax,0
|
---|
561 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
---|
562 |
|
---|
563 | ErrorStep:
|
---|
564 |
|
---|
565 | //je ...
|
---|
566 | pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );
|
---|
567 |
|
---|
568 | //レキシカルスコープをレベルアップ
|
---|
569 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_FOR );
|
---|
570 |
|
---|
571 | //For内をコンパイル
|
---|
572 | CompileBuffer(0,COM_NEXT);
|
---|
573 |
|
---|
574 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
---|
575 |
|
---|
576 | if(szNextVariable[0]){
|
---|
577 | if(lstrcmp(szNextVariable,variable)!=0){
|
---|
578 | SetError(55,szNextVariable,cp);
|
---|
579 | }
|
---|
580 | }
|
---|
581 |
|
---|
582 | //jmp ...
|
---|
583 | compiler.codeGenerator.op_jmp_continue();
|
---|
584 |
|
---|
585 | //レキシカルスコープをレベルダウン
|
---|
586 | compiler.codeGenerator.lexicalScopes.End();
|
---|
587 |
|
---|
588 | //jeジャンプ先のオフセット値
|
---|
589 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
590 |
|
---|
591 | //Continueアドレスを復元
|
---|
592 | compiler.codeGenerator.ContinueAreaEnd();
|
---|
593 | }
|
---|
594 |
|
---|
595 | void OpcodeDo(char *Parameter){
|
---|
596 | extern HANDLE hHeap;
|
---|
597 | int i,i2,i3;
|
---|
598 |
|
---|
599 | if(Parameter[0]) SetError(10,"Do",cp);
|
---|
600 |
|
---|
601 | //Continueアドレスのバックアップとセット
|
---|
602 | compiler.codeGenerator.ContinueAreaBegin();
|
---|
603 |
|
---|
604 | //レキシカルスコープをレベルアップ
|
---|
605 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_DO );
|
---|
606 |
|
---|
607 | //Do内をコンパイル
|
---|
608 | CompileBuffer(0,COM_LOOP);
|
---|
609 |
|
---|
610 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
---|
611 |
|
---|
612 | const PertialSchedule *pDoPertialSchedule = NULL;
|
---|
613 |
|
---|
614 | extern char *basbuf;
|
---|
615 | char temporary[VN_SIZE];
|
---|
616 | for(i=cp-1;;i--){
|
---|
617 | if(IsCommandDelimitation(basbuf[i])){
|
---|
618 | i+=3;
|
---|
619 | if(!(basbuf[i]=='0'||basbuf[i]=='1')){
|
---|
620 | //無条件ループ
|
---|
621 | break;
|
---|
622 | }
|
---|
623 | i3=i;
|
---|
624 |
|
---|
625 | for(i+=2,i2=0;;i++,i2++){
|
---|
626 | if(IsCommandDelimitation(basbuf[i])){
|
---|
627 | temporary[i2]=0;
|
---|
628 | break;
|
---|
629 | }
|
---|
630 | temporary[i2]=basbuf[i];
|
---|
631 | }
|
---|
632 |
|
---|
633 | Type tempType;
|
---|
634 | NumOpe(temporary,Type(),tempType);
|
---|
635 |
|
---|
636 | if( tempType.IsDouble() ){
|
---|
637 | //fld qword ptr[esp]
|
---|
638 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
---|
639 |
|
---|
640 | //push 0
|
---|
641 | compiler.codeGenerator.op_push_V(0);
|
---|
642 |
|
---|
643 | //fild dword ptr[esp]
|
---|
644 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
---|
645 |
|
---|
646 | //add esp,sizeof(double)+sizeof(long)
|
---|
647 | compiler.codeGenerator.op_add_esp(sizeof(double)+sizeof(long));
|
---|
648 |
|
---|
649 | //fcompp
|
---|
650 | compiler.codeGenerator.op_fcompp();
|
---|
651 |
|
---|
652 | //fnstsw ax
|
---|
653 | compiler.codeGenerator.op_fnstsw_ax();
|
---|
654 |
|
---|
655 | //test ah,40
|
---|
656 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
---|
657 |
|
---|
658 | if(basbuf[i3]=='0'){
|
---|
659 | //While
|
---|
660 |
|
---|
661 | //jne 5(ループ終了)
|
---|
662 | pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
---|
663 | }
|
---|
664 | else if(basbuf[i3]=='1'){
|
---|
665 | //Until
|
---|
666 |
|
---|
667 | //je 5(ループ終了)
|
---|
668 | pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true );
|
---|
669 | }
|
---|
670 | }
|
---|
671 | else if( tempType.IsSingle() ){
|
---|
672 | //fld dword ptr[esp]
|
---|
673 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
---|
674 |
|
---|
675 | //push 0
|
---|
676 | compiler.codeGenerator.op_push_V(0);
|
---|
677 |
|
---|
678 | //fild dword ptr[esp]
|
---|
679 | compiler.codeGenerator.op_fld_ptr_esp(DEF_LONG);
|
---|
680 |
|
---|
681 | //add esp,sizeof(float)+sizeof(long)
|
---|
682 | compiler.codeGenerator.op_add_esp(sizeof(float)+sizeof(long));
|
---|
683 |
|
---|
684 | //fcompp
|
---|
685 | compiler.codeGenerator.op_fcompp();
|
---|
686 |
|
---|
687 | //fnstsw ax
|
---|
688 | compiler.codeGenerator.op_fnstsw_ax();
|
---|
689 |
|
---|
690 | //test ah,40
|
---|
691 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
---|
692 |
|
---|
693 | if(basbuf[i3]=='0'){
|
---|
694 | //While
|
---|
695 |
|
---|
696 | //jne 5(ループ終了)
|
---|
697 | pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
---|
698 | }
|
---|
699 | else if(basbuf[i3]=='1'){
|
---|
700 | //Until
|
---|
701 |
|
---|
702 | //je 5(ループ終了)
|
---|
703 | pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true );
|
---|
704 | }
|
---|
705 | }
|
---|
706 | else if( tempType.Is64() ){
|
---|
707 | //64ビット型
|
---|
708 |
|
---|
709 | //pop eax
|
---|
710 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
711 |
|
---|
712 | //pop ebx
|
---|
713 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
714 |
|
---|
715 | //cmp eax,0
|
---|
716 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
---|
717 |
|
---|
718 | //jne
|
---|
719 | const PertialSchedule *pTempPertialSchedule1 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
---|
720 |
|
---|
721 | //cmp ebx,0
|
---|
722 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EBX, 0 );
|
---|
723 |
|
---|
724 | //jne
|
---|
725 | const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
---|
726 |
|
---|
727 | if(basbuf[i3]=='0'){
|
---|
728 | //While
|
---|
729 |
|
---|
730 | //jmp 5(ループ終了)
|
---|
731 | pDoPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
|
---|
732 |
|
---|
733 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 );
|
---|
734 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 );
|
---|
735 | }
|
---|
736 | else if(basbuf[i3]=='1'){
|
---|
737 | //Until
|
---|
738 |
|
---|
739 | //jmp 2(ループを続ける)
|
---|
740 | const PertialSchedule *pTempPertialSchedule3 = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
|
---|
741 |
|
---|
742 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule1 );
|
---|
743 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 );
|
---|
744 |
|
---|
745 | //jmp 5(ループ終了)
|
---|
746 | pDoPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(char), true );
|
---|
747 |
|
---|
748 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule3 );
|
---|
749 | }
|
---|
750 | }
|
---|
751 | else{
|
---|
752 | //pop eax
|
---|
753 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
754 |
|
---|
755 | //cmp eax,0
|
---|
756 | compiler.codeGenerator.op_cmp_value( sizeof(long), REG_EAX, 0 );
|
---|
757 |
|
---|
758 | if(basbuf[i3]=='0'){
|
---|
759 | //While
|
---|
760 |
|
---|
761 | //je 5(ループ終了)
|
---|
762 | pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true );
|
---|
763 | }
|
---|
764 | else if(basbuf[i3]=='1'){
|
---|
765 | //Until
|
---|
766 |
|
---|
767 | //jne 5(ループ終了)
|
---|
768 | pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
---|
769 | }
|
---|
770 | }
|
---|
771 | break;
|
---|
772 | }
|
---|
773 | }
|
---|
774 |
|
---|
775 | //jmp ...
|
---|
776 | compiler.codeGenerator.op_jmp_continue();
|
---|
777 |
|
---|
778 | if( pDoPertialSchedule )
|
---|
779 | {
|
---|
780 | compiler.codeGenerator.opfix_JmpPertialSchedule( pDoPertialSchedule );
|
---|
781 | }
|
---|
782 |
|
---|
783 | //jmp ...
|
---|
784 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
---|
785 |
|
---|
786 | //レキシカルスコープをレベルダウン
|
---|
787 | compiler.codeGenerator.lexicalScopes.End();
|
---|
788 |
|
---|
789 | //jmpジャンプ先のオフセット値
|
---|
790 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
791 |
|
---|
792 | //Continueアドレスを復元
|
---|
793 | compiler.codeGenerator.ContinueAreaEnd();
|
---|
794 | }
|
---|
795 | void OpcodeContinue(void){
|
---|
796 | //jmp ...(Continue addr)
|
---|
797 | compiler.codeGenerator.op_jmp_continue();
|
---|
798 | }
|
---|
799 |
|
---|
800 | void OpcodeExitSub(void){
|
---|
801 | if( UserProc::IsGlobalAreaCompiling() ){
|
---|
802 | SetError(12,"Exit Sub/Function",cp);
|
---|
803 | return;
|
---|
804 | }
|
---|
805 |
|
---|
806 | //未解放のローカルオブジェクトのデストラクタを呼び出す
|
---|
807 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfReturn();
|
---|
808 |
|
---|
809 | //jmp ...(End Sub/Function)
|
---|
810 | compiler.codeGenerator.op_jmp_exitsub();
|
---|
811 | }
|
---|
812 |
|
---|
813 | //Caseスケジュール
|
---|
814 | class SelectSchedule
|
---|
815 | {
|
---|
816 | public:
|
---|
817 | SelectSchedule( int typeSize )
|
---|
818 | : typeSize( typeSize )
|
---|
819 | , nowCaseSchedule( 0 )
|
---|
820 | {
|
---|
821 | }
|
---|
822 |
|
---|
823 | PertialSchedules casePertialSchedules;
|
---|
824 | int typeSize;
|
---|
825 | int nowCaseSchedule;
|
---|
826 | };
|
---|
827 | std::vector<SelectSchedule> selectSchedules;
|
---|
828 |
|
---|
829 | void OpcodeSelect(const char *lpszParms){
|
---|
830 | extern HANDLE hHeap;
|
---|
831 | extern char *basbuf;
|
---|
832 | int i,i2,i3,sw,NowCaseCp;
|
---|
833 | char temporary[VN_SIZE];
|
---|
834 |
|
---|
835 | Type type1;
|
---|
836 | if( !NumOpe(lpszParms,Type(), type1 ) ){
|
---|
837 | return;
|
---|
838 | }
|
---|
839 |
|
---|
840 | selectSchedules.push_back( SelectSchedule( type1.GetSize() ) );
|
---|
841 |
|
---|
842 | if( selectSchedules.back().typeSize < sizeof(long) ){
|
---|
843 | selectSchedules.back().typeSize = sizeof(long);
|
---|
844 | }
|
---|
845 |
|
---|
846 | for(i=cp,sw=0;;i++){
|
---|
847 | if(basbuf[i]=='\0'){
|
---|
848 | selectSchedules.pop_back();
|
---|
849 | SetError(22,"Select",cp);
|
---|
850 | return;
|
---|
851 | }
|
---|
852 | if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE){
|
---|
853 | for(i2=0;;i++){
|
---|
854 | if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE) i2++;
|
---|
855 | if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){
|
---|
856 | i2--;
|
---|
857 | if(i2==0) break;
|
---|
858 | }
|
---|
859 | }
|
---|
860 | continue;
|
---|
861 | }
|
---|
862 | if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){
|
---|
863 | if(sw==0){
|
---|
864 | //add esp,CaseTypeSize
|
---|
865 | compiler.codeGenerator.op_add_esp( selectSchedules.back().typeSize );
|
---|
866 | }
|
---|
867 | break;
|
---|
868 | }
|
---|
869 | if(basbuf[i]==1&&basbuf[i+1]==ESC_CASE){
|
---|
870 | NowCaseCp=i;
|
---|
871 |
|
---|
872 | i++;
|
---|
873 | while(1){
|
---|
874 | for(i++,i2=0;;i++,i2++){
|
---|
875 | if(basbuf[i]=='\"'){
|
---|
876 | i3=GetStringInQuotation(temporary+i2,basbuf+i);
|
---|
877 | i+=i3-1;
|
---|
878 | i2+=i3-1;
|
---|
879 | continue;
|
---|
880 | }
|
---|
881 | if(basbuf[i]=='('){
|
---|
882 | i3=GetStringInPare(temporary+i2,basbuf+i);
|
---|
883 | i+=i3-1;
|
---|
884 | i2+=i3-1;
|
---|
885 | continue;
|
---|
886 | }
|
---|
887 | if(basbuf[i]=='['){
|
---|
888 | i3=GetStringInBracket(temporary+i2,basbuf+i);
|
---|
889 | i+=i3-1;
|
---|
890 | i2+=i3-1;
|
---|
891 | continue;
|
---|
892 | }
|
---|
893 |
|
---|
894 | if(IsCommandDelimitation(basbuf[i])){
|
---|
895 | temporary[i2]=0;
|
---|
896 | break;
|
---|
897 | }
|
---|
898 | if(basbuf[i]==','){
|
---|
899 | temporary[i2]=0;
|
---|
900 | break;
|
---|
901 | }
|
---|
902 |
|
---|
903 | temporary[i2]=basbuf[i];
|
---|
904 | }
|
---|
905 |
|
---|
906 | //エラー用
|
---|
907 | i2=cp;
|
---|
908 | cp=NowCaseCp;
|
---|
909 |
|
---|
910 | Type type2;
|
---|
911 | if( !NumOpe(temporary,type1,type2) ){
|
---|
912 | return;
|
---|
913 | }
|
---|
914 |
|
---|
915 | cp=i2;
|
---|
916 |
|
---|
917 | if(type1.IsObject()){
|
---|
918 | std::vector<const UserProc *> subs;
|
---|
919 | type1.GetClass().GetDynamicMethods().Enum( CALC_EQUAL, subs );
|
---|
920 | if( subs.size() == 0 ){
|
---|
921 | return;
|
---|
922 | }
|
---|
923 |
|
---|
924 | Parameters params;
|
---|
925 | params.push_back( new Parameter( "", Type( type2 ) ) );
|
---|
926 |
|
---|
927 | //オーバーロードを解決
|
---|
928 | const UserProc *pUserProc = OverloadSolution("==",subs, params, NULL);
|
---|
929 |
|
---|
930 | delete params[0];
|
---|
931 |
|
---|
932 | if(!pUserProc){
|
---|
933 | //エラー
|
---|
934 | return;
|
---|
935 | }
|
---|
936 |
|
---|
937 |
|
---|
938 | //pop edx
|
---|
939 | compiler.codeGenerator.op_pop(REG_EDX);
|
---|
940 |
|
---|
941 | //mov ecx,dword ptr[esp]
|
---|
942 | compiler.codeGenerator.op_mov_RM(sizeof(long),REG_ECX,REG_ESP,0,MOD_BASE);
|
---|
943 |
|
---|
944 | //push edx
|
---|
945 | compiler.codeGenerator.op_push(REG_EDX);
|
---|
946 |
|
---|
947 | //push ecx
|
---|
948 | compiler.codeGenerator.op_push(REG_ECX);
|
---|
949 |
|
---|
950 | //call operator_proc ※ ==演算子
|
---|
951 | compiler.codeGenerator.op_call(pUserProc);
|
---|
952 |
|
---|
953 | //test eax,eax
|
---|
954 | compiler.codeGenerator.op_test(REG_EAX,REG_EAX);
|
---|
955 |
|
---|
956 | //jne ...
|
---|
957 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
958 | compiler.codeGenerator.op_jne( 0, sizeof(long), true )
|
---|
959 | );
|
---|
960 | }
|
---|
961 | else if(type1.IsDouble()){
|
---|
962 | ChangeTypeToDouble(type2.GetBasicType());
|
---|
963 |
|
---|
964 | //fld qword ptr[esp]
|
---|
965 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
---|
966 |
|
---|
967 | //add esp,CaseTypeSize
|
---|
968 | compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize);
|
---|
969 |
|
---|
970 | //fld qword ptr[esp]
|
---|
971 | compiler.codeGenerator.op_fld_ptr_esp(DEF_DOUBLE);
|
---|
972 |
|
---|
973 | //fcompp
|
---|
974 | compiler.codeGenerator.op_fcompp();
|
---|
975 |
|
---|
976 | //fnstsw ax
|
---|
977 | compiler.codeGenerator.op_fnstsw_ax();
|
---|
978 |
|
---|
979 | //test ah,40
|
---|
980 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
---|
981 |
|
---|
982 | //jne ...
|
---|
983 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
984 | compiler.codeGenerator.op_jne( 0, sizeof(long), true )
|
---|
985 | );
|
---|
986 | }
|
---|
987 | else if(type1.IsSingle()){
|
---|
988 | ChangeTypeToSingle(type2.GetBasicType());
|
---|
989 |
|
---|
990 | //fld dword ptr[esp]
|
---|
991 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
---|
992 |
|
---|
993 | //add esp,CaseTypeSize
|
---|
994 | compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize);
|
---|
995 |
|
---|
996 | //fld dword ptr[esp]
|
---|
997 | compiler.codeGenerator.op_fld_ptr_esp(DEF_SINGLE);
|
---|
998 |
|
---|
999 | //fcompp
|
---|
1000 | compiler.codeGenerator.op_fcompp();
|
---|
1001 |
|
---|
1002 | //fnstsw ax
|
---|
1003 | compiler.codeGenerator.op_fnstsw_ax();
|
---|
1004 |
|
---|
1005 | //test ah,40
|
---|
1006 | compiler.codeGenerator.op_test_ah( (char)0x40 );
|
---|
1007 |
|
---|
1008 | //jne ...
|
---|
1009 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
1010 | compiler.codeGenerator.op_jne( 0, sizeof(long), true )
|
---|
1011 | );
|
---|
1012 | }
|
---|
1013 | else{
|
---|
1014 | //その他整数型
|
---|
1015 |
|
---|
1016 | //pop ebx
|
---|
1017 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
1018 |
|
---|
1019 | //mov eax,dword ptr[esp]
|
---|
1020 | compiler.codeGenerator.op_mov_RM( sizeof(long), REG_EAX, REG_ESP, 0, MOD_BASE );
|
---|
1021 |
|
---|
1022 | //cmp eax,ebx
|
---|
1023 | compiler.codeGenerator.op_cmp_RR( REG_EAX, REG_EBX );
|
---|
1024 |
|
---|
1025 | //je ...
|
---|
1026 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
1027 | compiler.codeGenerator.op_je( 0, sizeof(long), true )
|
---|
1028 | );
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | if(basbuf[i]!=',') break;
|
---|
1032 | }
|
---|
1033 | }
|
---|
1034 | if(basbuf[i]==1&&basbuf[i+1]==ESC_CASEELSE){
|
---|
1035 | sw=1;
|
---|
1036 |
|
---|
1037 | //jmp ...
|
---|
1038 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
1039 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
|
---|
1040 | );
|
---|
1041 | }
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | //レキシカルスコープをレベルアップ
|
---|
1045 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_SELECT );
|
---|
1046 |
|
---|
1047 | //Select Case内をコンパイル
|
---|
1048 | CompileBuffer(ESC_ENDSELECT,0);
|
---|
1049 |
|
---|
1050 | //jmp EndSelect
|
---|
1051 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
1052 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
|
---|
1053 | );
|
---|
1054 |
|
---|
1055 | //最終スケジュール
|
---|
1056 | for(i=selectSchedules.back().nowCaseSchedule;i<(int)selectSchedules.back().casePertialSchedules.size();i++){
|
---|
1057 | compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[i] );
|
---|
1058 | }
|
---|
1059 |
|
---|
1060 | //レキシカルスコープをレベルダウン
|
---|
1061 | compiler.codeGenerator.lexicalScopes.End();
|
---|
1062 |
|
---|
1063 | selectSchedules.pop_back();
|
---|
1064 | }
|
---|
1065 | void OpcodeCase(char *Parameter){
|
---|
1066 | int i;
|
---|
1067 |
|
---|
1068 | if(selectSchedules.back().typeSize==-1){
|
---|
1069 | SetError(30,"Case",cp);
|
---|
1070 | return;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | //jmp EndSelect
|
---|
1074 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
1075 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
|
---|
1076 | );
|
---|
1077 |
|
---|
1078 | i=0;
|
---|
1079 | while(1){
|
---|
1080 | //Caseスケジュール
|
---|
1081 | compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[selectSchedules.back().nowCaseSchedule] );
|
---|
1082 | selectSchedules.back().nowCaseSchedule++;
|
---|
1083 |
|
---|
1084 | i=JumpOneParameter(Parameter,i);
|
---|
1085 | if(Parameter[i]=='\0') break;
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | //add esp,CaseTypeSize
|
---|
1089 | compiler.codeGenerator.op_add_esp(selectSchedules.back().typeSize);
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | void OpcodeGosub(char *Parameter){
|
---|
1093 | extern HANDLE hHeap;
|
---|
1094 | int i,LineNum;
|
---|
1095 |
|
---|
1096 | if(Parameter[0]=='*'){
|
---|
1097 | i=GetLabelAddress(Parameter+1,0);
|
---|
1098 |
|
---|
1099 | if( i == -1 )
|
---|
1100 | {
|
---|
1101 | //jmp ...(schedule)
|
---|
1102 | compiler.codeGenerator.op_jmp_goto_schedule( (const std::string)(Parameter + 1), 0, cp );
|
---|
1103 | }
|
---|
1104 | else
|
---|
1105 | {
|
---|
1106 | //jmp ...
|
---|
1107 | compiler.codeGenerator.op_jmp(
|
---|
1108 | i-compiler.codeGenerator.GetNativeCodeSize(),
|
---|
1109 | sizeof(long),
|
---|
1110 | false,
|
---|
1111 | true
|
---|
1112 | );
|
---|
1113 | }
|
---|
1114 | }
|
---|
1115 | else{
|
---|
1116 | LineNum=atoi(Parameter);
|
---|
1117 | i=GetLabelAddress(0,LineNum);
|
---|
1118 |
|
---|
1119 | if( i == -1 )
|
---|
1120 | {
|
---|
1121 | //jmp ...(schedule)
|
---|
1122 | compiler.codeGenerator.op_jmp_goto_schedule( "", LineNum, cp );
|
---|
1123 | }
|
---|
1124 | else
|
---|
1125 | {
|
---|
1126 | //jmp ...
|
---|
1127 | compiler.codeGenerator.op_jmp(
|
---|
1128 | i-compiler.codeGenerator.GetNativeCodeSize(),
|
---|
1129 | sizeof(long),
|
---|
1130 | false,
|
---|
1131 | true
|
---|
1132 | );
|
---|
1133 | }
|
---|
1134 | }
|
---|
1135 | }
|
---|
1136 | void OpcodeReturn(char *Parameter){
|
---|
1137 | if( UserProc::IsGlobalAreaCompiling() ){
|
---|
1138 | //Gosub~Returnとして扱う
|
---|
1139 |
|
---|
1140 | //ret
|
---|
1141 | compiler.codeGenerator.op_ret();
|
---|
1142 | }
|
---|
1143 | else{
|
---|
1144 | //戻り値をセット
|
---|
1145 | if(Parameter[0]){
|
---|
1146 | const UserProc &proc = UserProc::CompilingUserProc();
|
---|
1147 |
|
---|
1148 | const char *temp = "_System_ReturnValue";
|
---|
1149 | if(proc.GetName()[0]==1&&proc.GetName()[1]==ESC_OPERATOR)
|
---|
1150 | {
|
---|
1151 | }
|
---|
1152 | else{
|
---|
1153 | temp=proc.GetName().c_str();
|
---|
1154 | }
|
---|
1155 |
|
---|
1156 | char temporary[VN_SIZE];
|
---|
1157 | sprintf(temporary,"%s=%s",temp,Parameter);
|
---|
1158 | OpcodeCalc(temporary);
|
---|
1159 | }
|
---|
1160 |
|
---|
1161 | //プロシージャを抜け出す(C言語のreturnと同様の処理を行う)
|
---|
1162 | OpcodeExitSub();
|
---|
1163 | }
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 |
|
---|
1167 | ////////////
|
---|
1168 | // ポインタ
|
---|
1169 |
|
---|
1170 | void OpcodeSetPtrData(char *Parameter,int type){
|
---|
1171 | int i;
|
---|
1172 | char temporary[VN_SIZE];
|
---|
1173 |
|
---|
1174 | if(Parameter[0]=='('){
|
---|
1175 | i=JumpStringInPare(Parameter,1);
|
---|
1176 | if(Parameter[i+1]=='\0'){
|
---|
1177 | for(i=0;;i++){
|
---|
1178 | Parameter[i]=Parameter[i+1];
|
---|
1179 | if(Parameter[i]=='\0') break;
|
---|
1180 | }
|
---|
1181 | Parameter[i-1]=0;
|
---|
1182 | }
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | //第1パラメータを取得
|
---|
1186 | i=GetOneParameter(Parameter,0,temporary);
|
---|
1187 | if(!Parameter[i]){
|
---|
1188 | SetError(1,NULL,cp);
|
---|
1189 | return;
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | Type resultType;
|
---|
1193 | if( !NumOpe(temporary,Type(),resultType) ){
|
---|
1194 | return;
|
---|
1195 | }
|
---|
1196 | if(!resultType.IsWhole()){
|
---|
1197 | SetError(11,Parameter,cp);
|
---|
1198 | return;
|
---|
1199 | }
|
---|
1200 |
|
---|
1201 | ChangeTypeToLong( resultType.GetBasicType() );
|
---|
1202 |
|
---|
1203 | //第2パラメータを取得
|
---|
1204 | i=GetOneParameter(Parameter,i,temporary);
|
---|
1205 | if(Parameter[i]){
|
---|
1206 | SetError(1,NULL,cp);
|
---|
1207 | return;
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 | if( !NumOpe(temporary,Type(),resultType) ){
|
---|
1211 | return;
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 | if(type==DEF_DOUBLE){
|
---|
1215 | ChangeTypeToDouble_ToFpuReg( resultType.GetBasicType() );
|
---|
1216 |
|
---|
1217 | //pop eax
|
---|
1218 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
1219 |
|
---|
1220 | //fstp qword ptr[eax]
|
---|
1221 | compiler.codeGenerator.PutOld(
|
---|
1222 | (char)0xDD,
|
---|
1223 | (char)0x18
|
---|
1224 | );
|
---|
1225 | }
|
---|
1226 | else if(type==DEF_SINGLE){
|
---|
1227 | ChangeTypeToSingle( resultType.GetBasicType() );
|
---|
1228 |
|
---|
1229 | //pop ebx
|
---|
1230 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
1231 |
|
---|
1232 | //pop eax
|
---|
1233 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
1234 |
|
---|
1235 | //mov dword ptr[eax],ebx
|
---|
1236 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EBX, REG_EAX, 0, MOD_BASE );
|
---|
1237 | }
|
---|
1238 | else if(type==DEF_QWORD){
|
---|
1239 | ChangeTypeToInt64( resultType.GetBasicType() );
|
---|
1240 |
|
---|
1241 | //pop ecx
|
---|
1242 | compiler.codeGenerator.op_pop(REG_ECX);
|
---|
1243 |
|
---|
1244 | //pop ebx
|
---|
1245 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
1246 |
|
---|
1247 | //pop eax
|
---|
1248 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
1249 |
|
---|
1250 | //mov dword ptr[eax],ecx
|
---|
1251 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_ECX, REG_EAX, 0, MOD_BASE );
|
---|
1252 |
|
---|
1253 | //mov dword ptr[eax+sizeof(long)],ebx
|
---|
1254 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EBX, REG_EAX, 0x04, MOD_BASE_DISP8 );
|
---|
1255 | }
|
---|
1256 | else if(type==DEF_DWORD){
|
---|
1257 | ChangeTypeToLong( resultType.GetBasicType() );
|
---|
1258 |
|
---|
1259 | //pop ebx
|
---|
1260 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
1261 |
|
---|
1262 | //pop eax
|
---|
1263 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
1264 |
|
---|
1265 | //mov dword ptr[eax],ebx
|
---|
1266 | compiler.codeGenerator.op_mov_MR( sizeof(long), REG_EBX, REG_EAX, 0, MOD_BASE );
|
---|
1267 | }
|
---|
1268 | else if(type==DEF_WORD){
|
---|
1269 | ChangeTypeToLong( resultType.GetBasicType() );
|
---|
1270 |
|
---|
1271 | //pop ebx
|
---|
1272 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
1273 |
|
---|
1274 | //pop eax
|
---|
1275 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
1276 |
|
---|
1277 | //mov word ptr[eax],bx
|
---|
1278 | compiler.codeGenerator.op_mov_MR( sizeof(short), REG_EBX, REG_EAX, 0, MOD_BASE );
|
---|
1279 | }
|
---|
1280 | else if(type==DEF_BYTE){
|
---|
1281 | ChangeTypeToLong( resultType.GetBasicType() );
|
---|
1282 |
|
---|
1283 | //pop ebx
|
---|
1284 | compiler.codeGenerator.op_pop(REG_EBX);
|
---|
1285 |
|
---|
1286 | //pop eax
|
---|
1287 | compiler.codeGenerator.op_pop(REG_EAX);
|
---|
1288 |
|
---|
1289 | //mov byte ptr[eax],bl
|
---|
1290 | compiler.codeGenerator.op_mov_MR( sizeof(char), REG_EBX, REG_EAX, 0, MOD_BASE );
|
---|
1291 | }
|
---|
1292 | }
|
---|