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