[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[183] | 3 | #include <jenga/include/smoothie/LexicalAnalysis.h>
|
---|
| 4 |
|
---|
| 5 | #include <Compiler.h>
|
---|
| 6 |
|
---|
[3] | 7 | #include "../BasicCompiler_Common/common.h"
|
---|
| 8 | #include "Opcode.h"
|
---|
| 9 |
|
---|
[129] | 10 | void OpcodeOthers(const char *Command){
|
---|
[3] | 11 | int i,i2;
|
---|
| 12 |
|
---|
[122] | 13 | char leftTerm[8192];
|
---|
| 14 | int lastParePos = 0;
|
---|
[3] | 15 | for(i=0;;i++){
|
---|
[122] | 16 | if(Command[i]=='\"'){
|
---|
| 17 | //ダブルクォートは不正なのでエラー扱い
|
---|
| 18 | leftTerm[i]=0;
|
---|
| 19 | SetError(3,leftTerm,cp);
|
---|
| 20 | return;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | if(Command[i]=='('){
|
---|
| 24 | lastParePos = i;
|
---|
| 25 | i2=GetStringInPare(leftTerm+i,Command+i);
|
---|
[3] | 26 | i+=i2-1;
|
---|
| 27 | continue;
|
---|
| 28 | }
|
---|
[122] | 29 | if(Command[i]=='['){
|
---|
| 30 | i2=GetStringInBracket(leftTerm+i,Command+i);
|
---|
| 31 | i+=i2-1;
|
---|
[3] | 32 | continue;
|
---|
| 33 | }
|
---|
[122] | 34 | if(Command[i]=='\0'){
|
---|
| 35 | leftTerm[i] = 0;
|
---|
[3] | 36 | break;
|
---|
| 37 | }
|
---|
[122] | 38 |
|
---|
| 39 | if( IsNumCalcMark( Command, i ) ){
|
---|
| 40 | leftTerm[i] = 0;
|
---|
| 41 | break;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | leftTerm[i]=Command[i];
|
---|
[3] | 45 | }
|
---|
| 46 | if(!(
|
---|
[122] | 47 | IsVariableTopChar(leftTerm[0])||
|
---|
| 48 | leftTerm[0]=='.'||
|
---|
| 49 | (leftTerm[0]==1&&leftTerm[1]==ESC_PSMEM)
|
---|
[3] | 50 | )){
|
---|
| 51 | SetError(1,NULL,cp);
|
---|
| 52 | return;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 |
|
---|
[122] | 56 | if(Command[i]=='\0' && lastParePos == 0){
|
---|
[3] | 57 | //////////////////////////////
|
---|
| 58 | // パラメータ無しのマクロ検索
|
---|
| 59 | //////////////////////////////
|
---|
| 60 |
|
---|
[206] | 61 | const UserProc *pUserProc=GetSubHash(Command);
|
---|
[3] | 62 |
|
---|
| 63 | //GetSubHash内でエラー提示が行われた場合
|
---|
[75] | 64 | if(pUserProc==(UserProc *)-1) return;
|
---|
[3] | 65 |
|
---|
[75] | 66 | if(pUserProc==0){
|
---|
[3] | 67 | char temporary[VN_SIZE];
|
---|
| 68 | lstrcpy(temporary,Command);
|
---|
| 69 |
|
---|
| 70 | CharUpper(temporary);
|
---|
[75] | 71 | pUserProc=GetSubHash(temporary);
|
---|
[3] | 72 |
|
---|
| 73 | //GetSubHash内でエラー提示が行われた場合
|
---|
[75] | 74 | if(pUserProc==(UserProc *)-1) return;
|
---|
[3] | 75 | }
|
---|
| 76 |
|
---|
[75] | 77 | if(pUserProc){
|
---|
[97] | 78 | if( !pUserProc->IsMacro() ){
|
---|
| 79 | SetError(10,Command,cp);
|
---|
| 80 | }
|
---|
[3] | 81 |
|
---|
[308] | 82 | Opcode_CallProc("",pUserProc,0,"");
|
---|
[3] | 83 |
|
---|
| 84 | return;
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | else if(IsNumCalcMark(Command,i)){
|
---|
| 88 | //代入演算
|
---|
| 89 | OpcodeCalc(Command);
|
---|
| 90 | return;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[122] | 93 | if( pobj_reg ){
|
---|
| 94 | SetError();
|
---|
| 95 | }
|
---|
| 96 | pobj_reg=new CRegister(REG_RAX);
|
---|
[3] | 97 |
|
---|
[370] | 98 | if( strstr(leftTerm,"赤"))
|
---|
| 99 | {
|
---|
| 100 | int test=0;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[122] | 103 | Type resultType;
|
---|
| 104 | bool isLiteral;
|
---|
| 105 | BOOL bUseHeap;
|
---|
[128] | 106 | bool result = TermOpe( leftTerm, Type(), resultType, isLiteral, &bUseHeap, false, NULL, true );
|
---|
[3] | 107 |
|
---|
[122] | 108 | delete pobj_reg;
|
---|
| 109 | pobj_reg = NULL;
|
---|
[3] | 110 |
|
---|
[122] | 111 | if( result ){
|
---|
[3] | 112 |
|
---|
| 113 | /////////////////////
|
---|
| 114 | // 戻り値の処理
|
---|
| 115 | /////////////////////
|
---|
| 116 |
|
---|
[75] | 117 | if( resultType.IsStruct() ){
|
---|
[3] | 118 | //mov r14,rax
|
---|
[226] | 119 | compiler.codeGenerator.op_mov_RR(REG_R14,REG_RAX);
|
---|
[3] | 120 |
|
---|
[75] | 121 | FreeTempObject(REG_R14,&resultType.GetClass());
|
---|
[3] | 122 | }
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | void Judgment(char *buffer){
|
---|
[75] | 127 | int reg=REG_RAX;
|
---|
| 128 | Type resultType;
|
---|
[326] | 129 | if( !NumOpe(®,buffer,Type(DEF_BOOLEAN),resultType) ){
|
---|
[75] | 130 | return;
|
---|
| 131 | }
|
---|
[3] | 132 |
|
---|
| 133 | int offset;
|
---|
| 134 |
|
---|
[75] | 135 | if(resultType.IsDouble()){
|
---|
[3] | 136 | double dbl=0;
|
---|
[266] | 137 | offset=compiler.GetObjectModule().dataTable.Add( dbl );
|
---|
[3] | 138 |
|
---|
| 139 | //comisd xmm0,qword ptr[data table offset]
|
---|
[242] | 140 | compiler.codeGenerator.PutOld(
|
---|
| 141 | (char)0x66,
|
---|
| 142 | (char)0x0F,
|
---|
| 143 | (char)0x2F,
|
---|
| 144 | (char)0x04,
|
---|
| 145 | (char)0x25
|
---|
| 146 | );
|
---|
| 147 | compiler.codeGenerator.PutOld(
|
---|
| 148 | (long)offset,
|
---|
| 149 | Schedule::DataTable
|
---|
| 150 | );
|
---|
[3] | 151 | }
|
---|
[75] | 152 | else if(resultType.IsSingle()){
|
---|
[3] | 153 | float flt=0;
|
---|
[266] | 154 | offset=compiler.GetObjectModule().dataTable.Add( flt );
|
---|
[3] | 155 |
|
---|
| 156 | //comiss xmm0,dword ptr[data table offset]
|
---|
[242] | 157 | compiler.codeGenerator.PutOld(
|
---|
| 158 | (char)0x0F,
|
---|
| 159 | (char)0x2F,
|
---|
| 160 | (char)0x04,
|
---|
| 161 | (char)0x25
|
---|
| 162 | );
|
---|
| 163 | compiler.codeGenerator.PutOld(
|
---|
| 164 | (long)offset,
|
---|
| 165 | Schedule::DataTable
|
---|
| 166 | );
|
---|
[3] | 167 | }
|
---|
| 168 | else{
|
---|
| 169 | //整数型
|
---|
| 170 |
|
---|
| 171 | //cmp rax,0
|
---|
[226] | 172 | compiler.codeGenerator.op_cmp_value(resultType.GetSize(),REG_RAX,0);
|
---|
[3] | 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | void OpcodeIf(char *Parameter){
|
---|
[242] | 177 | for(int i=0;;i++){
|
---|
[3] | 178 | if(Parameter[i]=='\0'){
|
---|
| 179 | SetError(21,NULL,cp);
|
---|
| 180 | return;
|
---|
| 181 | }
|
---|
| 182 | if(Parameter[i]==1&&Parameter[i+1]==ESC_THEN){
|
---|
| 183 | Parameter[i]=0;
|
---|
| 184 | break;
|
---|
| 185 | }
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | //条件式を実行してフラグをセット
|
---|
| 189 | Judgment(Parameter);
|
---|
| 190 |
|
---|
| 191 | //je (endif、または else まで条件ジャンプ)
|
---|
[254] | 192 | const PertialSchedule *pIfPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );
|
---|
[3] | 193 |
|
---|
| 194 |
|
---|
| 195 | /////////////////////////
|
---|
| 196 | // If内をコード化
|
---|
| 197 | /////////////////////////
|
---|
| 198 |
|
---|
| 199 | //レキシカルスコープをレベルアップ
|
---|
[308] | 200 | compiler.codeGenerator.lexicalScopes.Start(
|
---|
| 201 | compiler.codeGenerator.GetNativeCodeSize(),
|
---|
| 202 | LexicalScope::SCOPE_TYPE_IF
|
---|
| 203 | );
|
---|
[3] | 204 |
|
---|
[242] | 205 | int i2=CompileBuffer(ESC_ENDIF,0);
|
---|
[3] | 206 |
|
---|
| 207 | //レキシカルスコープをレベルダウン
|
---|
[254] | 208 | compiler.codeGenerator.lexicalScopes.End();
|
---|
[3] | 209 |
|
---|
| 210 |
|
---|
| 211 | if(i2==ESC_ELSE){
|
---|
| 212 | //jmp (endifまで)
|
---|
[254] | 213 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
---|
[3] | 214 |
|
---|
[242] | 215 | compiler.codeGenerator.opfix_JmpPertialSchedule( pIfPertialSchedule );
|
---|
[3] | 216 |
|
---|
| 217 |
|
---|
| 218 |
|
---|
| 219 | /////////////////////////
|
---|
| 220 | // Else内をコード化
|
---|
| 221 | /////////////////////////
|
---|
| 222 |
|
---|
| 223 | //レキシカルスコープをレベルアップ
|
---|
[308] | 224 | compiler.codeGenerator.lexicalScopes.Start(
|
---|
| 225 | compiler.codeGenerator.GetNativeCodeSize(),
|
---|
| 226 | LexicalScope::SCOPE_TYPE_IF
|
---|
| 227 | );
|
---|
[3] | 228 |
|
---|
| 229 | CompileBuffer(ESC_ENDIF,0);
|
---|
| 230 |
|
---|
| 231 | //レキシカルスコープをレベルダウン
|
---|
[254] | 232 | compiler.codeGenerator.lexicalScopes.End();
|
---|
[3] | 233 |
|
---|
| 234 |
|
---|
[242] | 235 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
[3] | 236 | }
|
---|
| 237 | else{
|
---|
[242] | 238 | compiler.codeGenerator.opfix_JmpPertialSchedule( pIfPertialSchedule );
|
---|
[3] | 239 | }
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | int GetLabelAddress(char *LabelName,int LineNum){
|
---|
| 243 | if(LabelName){
|
---|
[262] | 244 | BOOST_FOREACH( const GotoLabel &label, compiler.codeGenerator.gotoLabels )
|
---|
| 245 | {
|
---|
| 246 | if( label.name.size() > 0 )
|
---|
| 247 | {
|
---|
| 248 | if( label.name == LabelName )
|
---|
| 249 | {
|
---|
| 250 | return label.address;
|
---|
| 251 | }
|
---|
[3] | 252 | }
|
---|
| 253 | }
|
---|
| 254 | }
|
---|
| 255 | else{
|
---|
[262] | 256 | BOOST_FOREACH( const GotoLabel &label, compiler.codeGenerator.gotoLabels )
|
---|
| 257 | {
|
---|
| 258 | if( label.name.size() == 0 )
|
---|
| 259 | {
|
---|
| 260 | if( label.line == LineNum )
|
---|
| 261 | {
|
---|
| 262 | return label.address;
|
---|
| 263 | }
|
---|
[3] | 264 | }
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | return -1;
|
---|
| 268 | }
|
---|
| 269 | void OpcodeGoto(char *Parameter){
|
---|
| 270 | extern HANDLE hHeap;
|
---|
| 271 | int i,LineNum;
|
---|
| 272 |
|
---|
| 273 | if(Parameter[0]=='*'){
|
---|
| 274 | i=GetLabelAddress(Parameter+1,0);
|
---|
| 275 |
|
---|
[254] | 276 | if( i == -1 )
|
---|
| 277 | {
|
---|
| 278 | //jmp ...(schedule)
|
---|
| 279 | compiler.codeGenerator.op_jmp_goto_schedule( (const std::string)(Parameter + 1), 0, cp );
|
---|
[3] | 280 | }
|
---|
[254] | 281 | else
|
---|
| 282 | {
|
---|
| 283 | //jmp ...
|
---|
[308] | 284 | compiler.codeGenerator.op_jmp(
|
---|
| 285 | i-compiler.codeGenerator.GetNativeCodeSize(),
|
---|
| 286 | sizeof(long),
|
---|
| 287 | false,
|
---|
| 288 | true
|
---|
| 289 | );
|
---|
[254] | 290 | }
|
---|
[3] | 291 | }
|
---|
| 292 | else{
|
---|
| 293 | LineNum=atoi(Parameter);
|
---|
| 294 | i=GetLabelAddress(0,LineNum);
|
---|
| 295 |
|
---|
[254] | 296 | if( i == -1 )
|
---|
| 297 | {
|
---|
| 298 | //jmp ...(schedule)
|
---|
| 299 | compiler.codeGenerator.op_jmp_goto_schedule( "", LineNum, cp );
|
---|
[3] | 300 | }
|
---|
[254] | 301 | else
|
---|
| 302 | {
|
---|
| 303 | //jmp ...
|
---|
[308] | 304 | compiler.codeGenerator.op_jmp(
|
---|
| 305 | i-compiler.codeGenerator.GetNativeCodeSize(),
|
---|
| 306 | sizeof(long),
|
---|
| 307 | false,
|
---|
| 308 | true
|
---|
| 309 | );
|
---|
[254] | 310 | }
|
---|
[3] | 311 | }
|
---|
| 312 | }
|
---|
| 313 | void OpcodeWhile(char *Parameter){
|
---|
| 314 | extern HANDLE hHeap;
|
---|
| 315 |
|
---|
| 316 | //Continueアドレスのバックアップとセット
|
---|
[242] | 317 | compiler.codeGenerator.ContinueAreaBegin();
|
---|
[3] | 318 |
|
---|
| 319 | if(!Parameter[0]) SetError(10,"While",cp);
|
---|
| 320 |
|
---|
| 321 | //条件式を実行してフラグをセット
|
---|
| 322 | Judgment(Parameter);
|
---|
| 323 |
|
---|
| 324 | //je (Wend まで)
|
---|
[254] | 325 | const PertialSchedule *pWhilePertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );
|
---|
[3] | 326 |
|
---|
| 327 | //レキシカルスコープをレベルアップ
|
---|
[308] | 328 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_WHILE );
|
---|
[3] | 329 |
|
---|
| 330 | //While内をコンパイル
|
---|
| 331 | CompileBuffer(0,COM_WEND);
|
---|
| 332 |
|
---|
[254] | 333 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
---|
[3] | 334 |
|
---|
| 335 | //jmp ...
|
---|
[242] | 336 | compiler.codeGenerator.op_jmp_continue();
|
---|
[3] | 337 |
|
---|
| 338 | //レキシカルスコープをレベルダウン
|
---|
[254] | 339 | compiler.codeGenerator.lexicalScopes.End();
|
---|
[3] | 340 |
|
---|
[242] | 341 | compiler.codeGenerator.opfix_JmpPertialSchedule( pWhilePertialSchedule );
|
---|
[3] | 342 |
|
---|
| 343 | //Continueアドレスを復元
|
---|
[242] | 344 | compiler.codeGenerator.ContinueAreaEnd();
|
---|
[3] | 345 | }
|
---|
| 346 |
|
---|
| 347 | char szNextVariable[VN_SIZE];
|
---|
| 348 | void OpcodeFor(char *Parameter){
|
---|
| 349 | extern HANDLE hHeap;
|
---|
[75] | 350 | Type resultType;
|
---|
[242] | 351 | int i,i2;
|
---|
[3] | 352 | char temporary[VN_SIZE],variable[VN_SIZE],JudgeNum[VN_SIZE],StepNum[VN_SIZE];
|
---|
[34] | 353 | bool isError = false;
|
---|
[3] | 354 |
|
---|
| 355 | //第1パラメータを取得
|
---|
| 356 | i=GetOneParameter(Parameter,0,temporary);
|
---|
| 357 | if(!Parameter[i]){
|
---|
| 358 | SetError(12,"For",cp);
|
---|
[34] | 359 | isError = true;
|
---|
[3] | 360 | goto ErrorStep;
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | for(i2=0;;i2++){
|
---|
| 364 | if(temporary[i2]=='='){
|
---|
| 365 | variable[i2]=0;
|
---|
| 366 |
|
---|
| 367 | //カウンタ初期化
|
---|
| 368 | OpcodeCalc(temporary);
|
---|
| 369 | break;
|
---|
| 370 | }
|
---|
| 371 | if(temporary[i2]=='\0'){
|
---|
| 372 | SetError(12,"For",cp);
|
---|
[34] | 373 | isError = true;
|
---|
[3] | 374 | goto ErrorStep;
|
---|
| 375 | }
|
---|
| 376 | variable[i2]=temporary[i2];
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 | //jmp ...
|
---|
[254] | 380 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
---|
[3] | 381 |
|
---|
| 382 | //Continueアドレスのバックアップとセット
|
---|
[242] | 383 | compiler.codeGenerator.ContinueAreaBegin();
|
---|
[3] | 384 |
|
---|
| 385 | //第2パラメータを取得(to~)
|
---|
| 386 | i=GetOneParameter(Parameter,i,JudgeNum);
|
---|
| 387 |
|
---|
| 388 | //第3パラメータを取得(step~)
|
---|
| 389 | if(Parameter[i]){
|
---|
| 390 | i=GetOneParameter(Parameter,i,StepNum);
|
---|
| 391 | if(Parameter[i]) SetError(12,"For",cp);
|
---|
| 392 | }
|
---|
| 393 | else lstrcpy(StepNum,"1");
|
---|
| 394 |
|
---|
| 395 | //カウンタを増加させる
|
---|
| 396 | sprintf(temporary,"%s=(%s)+(%s)",variable,variable,StepNum);
|
---|
| 397 | OpcodeCalc(temporary);
|
---|
| 398 |
|
---|
[242] | 399 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
[3] | 400 |
|
---|
| 401 | //増加か減少かを区別する
|
---|
| 402 | sprintf(temporary,"(%s)>=0",StepNum);
|
---|
| 403 |
|
---|
[75] | 404 | int reg;
|
---|
[3] | 405 | reg=REG_RAX;
|
---|
[75] | 406 | if( !NumOpe(®,temporary,Type(),resultType) ){
|
---|
| 407 | return;
|
---|
| 408 | }
|
---|
[3] | 409 |
|
---|
| 410 | //cmp rax,0
|
---|
[226] | 411 | compiler.codeGenerator.op_cmp_value(resultType.GetSize(),REG_RAX,0);
|
---|
[3] | 412 |
|
---|
| 413 | //je [カウンタ減少の場合の判定]
|
---|
[242] | 414 | pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );
|
---|
[3] | 415 |
|
---|
| 416 | //判定(カウンタ増加の場合)
|
---|
| 417 | sprintf(temporary,"%s<=(%s)",variable,JudgeNum);
|
---|
| 418 |
|
---|
| 419 | reg=REG_RAX;
|
---|
[75] | 420 | NumOpe(®,temporary,Type(),Type());
|
---|
[3] | 421 |
|
---|
| 422 | //jmp [カウンタ減少の場合の判定を飛び越す]
|
---|
[254] | 423 | const PertialSchedule *pTempPertialSchedule2 = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
---|
[3] | 424 |
|
---|
[242] | 425 | //jeジャンプ先のオフセット値
|
---|
| 426 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
[3] | 427 |
|
---|
| 428 | //判定(カウンタ減少の場合)
|
---|
| 429 | sprintf(temporary,"%s>=(%s)",variable,JudgeNum);
|
---|
| 430 |
|
---|
| 431 | reg=REG_RAX;
|
---|
[75] | 432 | NumOpe(®,temporary,Type(),resultType);
|
---|
[3] | 433 |
|
---|
[242] | 434 | //jmpジャンプ先のオフセット値
|
---|
| 435 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule2 );
|
---|
[3] | 436 |
|
---|
| 437 | //cmp rax,0
|
---|
[226] | 438 | compiler.codeGenerator.op_cmp_value(resultType.GetSize(),REG_RAX,0);
|
---|
[3] | 439 |
|
---|
| 440 | ErrorStep:
|
---|
| 441 |
|
---|
| 442 | //je ...
|
---|
[242] | 443 | pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );
|
---|
[3] | 444 |
|
---|
| 445 | //レキシカルスコープをレベルアップ
|
---|
[308] | 446 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_FOR );
|
---|
[3] | 447 |
|
---|
| 448 | //For内をコンパイル
|
---|
| 449 | CompileBuffer(0,COM_NEXT);
|
---|
| 450 |
|
---|
[254] | 451 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
---|
[3] | 452 |
|
---|
| 453 | if(szNextVariable[0]){
|
---|
| 454 | if(lstrcmp(szNextVariable,variable)!=0){
|
---|
| 455 | SetError(55,szNextVariable,cp);
|
---|
| 456 | }
|
---|
| 457 | }
|
---|
| 458 |
|
---|
| 459 | //jmp ...
|
---|
[242] | 460 | compiler.codeGenerator.op_jmp_continue();
|
---|
[3] | 461 |
|
---|
| 462 | //レキシカルスコープをレベルダウン
|
---|
[254] | 463 | compiler.codeGenerator.lexicalScopes.End();
|
---|
[3] | 464 |
|
---|
[242] | 465 | //jeジャンプ先のオフセット値
|
---|
| 466 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
[3] | 467 |
|
---|
| 468 | //Continueアドレスを復元
|
---|
[242] | 469 | compiler.codeGenerator.ContinueAreaEnd();
|
---|
[3] | 470 | }
|
---|
| 471 |
|
---|
[372] | 472 | void OpcodeForeach( const char *Parameter )
|
---|
| 473 | {
|
---|
| 474 | Type resultType;
|
---|
| 475 | int i;
|
---|
| 476 | char temporary[VN_SIZE],variable[VN_SIZE],collectionVar[VN_SIZE];
|
---|
| 477 | bool isError = false;
|
---|
| 478 |
|
---|
| 479 | //第1パラメータを取得
|
---|
| 480 | i=GetOneParameter(Parameter,0,temporary);
|
---|
| 481 | if(!Parameter[i]){
|
---|
| 482 | SetError(12,"Foreach",cp);
|
---|
| 483 | isError = true;
|
---|
| 484 | goto ErrorStep;
|
---|
| 485 | }
|
---|
| 486 |
|
---|
| 487 | lstrcpy( variable, temporary );
|
---|
| 488 |
|
---|
| 489 | //第2パラメータを取得(in~)
|
---|
| 490 | i=GetOneParameter(Parameter,i,collectionVar);
|
---|
| 491 |
|
---|
[375] | 492 | if( !GetVarType( variable, resultType, false ) )
|
---|
| 493 | {
|
---|
| 494 | Type collectionType;
|
---|
| 495 | if( !NumOpe_GetType( collectionVar, Type(), collectionType ) )
|
---|
| 496 | {
|
---|
| 497 | isError = true;
|
---|
| 498 | goto ErrorStep;
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 | // 未定義の場合は自動的に定義する
|
---|
| 502 | sprintf(temporary,"%s%c%c%s", variable, 1, ESC_AS, collectionType.GetActualGenericType(0).GetClass().GetFullName().c_str() );
|
---|
| 503 | MessageBox(0,temporary,"test",0);
|
---|
| 504 | OpcodeDim(temporary,DIMFLAG_INITDEBUGVAR);
|
---|
| 505 | }
|
---|
| 506 |
|
---|
[372] | 507 | // Resetメソッドを呼び出す
|
---|
| 508 | sprintf( temporary, "%s.Reset()", collectionVar );
|
---|
| 509 | Compile( temporary );
|
---|
| 510 |
|
---|
| 511 | //Continueアドレスのバックアップとセット
|
---|
| 512 | compiler.codeGenerator.ContinueAreaBegin();
|
---|
| 513 |
|
---|
| 514 | // MoveNextメソッドを呼び出す
|
---|
| 515 | sprintf( temporary, "%s.MoveNext()", collectionVar );
|
---|
| 516 | int reg = REG_RAX;
|
---|
| 517 | NumOpe(®,temporary,Type(),resultType);
|
---|
| 518 |
|
---|
| 519 | //cmp rax,0
|
---|
| 520 | compiler.codeGenerator.op_cmp_value(resultType.GetSize(),REG_RAX,0);
|
---|
| 521 |
|
---|
| 522 | ErrorStep:
|
---|
| 523 |
|
---|
| 524 | //je ...
|
---|
| 525 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(long), true );
|
---|
| 526 |
|
---|
| 527 | //レキシカルスコープをレベルアップ
|
---|
| 528 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_FOR );
|
---|
| 529 |
|
---|
| 530 | // Currentプロパティから現在の値を取得
|
---|
| 531 | // TODO: 型指定が未完成
|
---|
| 532 | sprintf( temporary, "%s=%s.Current As String", variable, collectionVar );
|
---|
| 533 | Compile( temporary );
|
---|
| 534 |
|
---|
| 535 | //For内をコンパイル
|
---|
| 536 | CompileBuffer(0,COM_NEXT);
|
---|
| 537 |
|
---|
| 538 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
---|
| 539 |
|
---|
| 540 | if(szNextVariable[0]){
|
---|
| 541 | if(lstrcmp(szNextVariable,variable)!=0){
|
---|
| 542 | SetError(55,szNextVariable,cp);
|
---|
| 543 | }
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 | //jmp ...
|
---|
| 547 | compiler.codeGenerator.op_jmp_continue();
|
---|
| 548 |
|
---|
| 549 | //レキシカルスコープをレベルダウン
|
---|
| 550 | compiler.codeGenerator.lexicalScopes.End();
|
---|
| 551 |
|
---|
| 552 | //jeジャンプ先のオフセット値
|
---|
| 553 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
| 554 |
|
---|
| 555 | //Continueアドレスを復元
|
---|
| 556 | compiler.codeGenerator.ContinueAreaEnd();
|
---|
| 557 | }
|
---|
| 558 |
|
---|
[3] | 559 | void OpcodeDo(char *Parameter){
|
---|
| 560 | extern HANDLE hHeap;
|
---|
| 561 | int i,i2,i3;
|
---|
| 562 |
|
---|
| 563 | if(Parameter[0]) SetError(10,"Do",cp);
|
---|
| 564 |
|
---|
| 565 | //Continueアドレスのバックアップとセット
|
---|
[242] | 566 | compiler.codeGenerator.ContinueAreaBegin();
|
---|
[3] | 567 |
|
---|
| 568 | //レキシカルスコープをレベルアップ
|
---|
[308] | 569 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_DO );
|
---|
[3] | 570 |
|
---|
| 571 | //Do内をコンパイル
|
---|
| 572 | CompileBuffer(0,COM_LOOP);
|
---|
| 573 |
|
---|
[254] | 574 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfScopeEnd();
|
---|
[3] | 575 |
|
---|
[254] | 576 | const PertialSchedule *pDoPertialSchedule = NULL;
|
---|
[242] | 577 |
|
---|
[3] | 578 | extern char *basbuf;
|
---|
| 579 | char temporary[VN_SIZE];
|
---|
| 580 | for(i=cp-1;;i--){
|
---|
| 581 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 582 | i+=3;
|
---|
| 583 | if(!(basbuf[i]=='0'||basbuf[i]=='1')){
|
---|
| 584 | //無条件ループ
|
---|
| 585 | break;
|
---|
| 586 | }
|
---|
| 587 | i3=i;
|
---|
| 588 |
|
---|
| 589 | for(i+=2,i2=0;;i++,i2++){
|
---|
| 590 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 591 | temporary[i2]=0;
|
---|
| 592 | break;
|
---|
| 593 | }
|
---|
| 594 | temporary[i2]=basbuf[i];
|
---|
| 595 | }
|
---|
| 596 |
|
---|
| 597 | //条件式を実行してフラグをセット
|
---|
| 598 | Judgment(temporary);
|
---|
| 599 |
|
---|
| 600 | if(basbuf[i3]=='0'){
|
---|
| 601 | //While
|
---|
| 602 |
|
---|
| 603 | //je 5(ループ終了)
|
---|
[242] | 604 | pDoPertialSchedule = compiler.codeGenerator.op_je( 0, sizeof(char), true );
|
---|
[3] | 605 | }
|
---|
| 606 | else if(basbuf[i3]=='1'){
|
---|
| 607 | //Until
|
---|
| 608 |
|
---|
| 609 | //jne 5(ループ終了)
|
---|
[242] | 610 | pDoPertialSchedule = compiler.codeGenerator.op_jne( 0, sizeof(char), true );
|
---|
[3] | 611 | }
|
---|
| 612 | break;
|
---|
| 613 | }
|
---|
| 614 | }
|
---|
| 615 |
|
---|
| 616 | //jmp ...
|
---|
[242] | 617 | compiler.codeGenerator.op_jmp_continue();
|
---|
[3] | 618 |
|
---|
[242] | 619 | if( pDoPertialSchedule )
|
---|
| 620 | {
|
---|
| 621 | compiler.codeGenerator.opfix_JmpPertialSchedule( pDoPertialSchedule );
|
---|
| 622 | }
|
---|
| 623 |
|
---|
[3] | 624 | //jmp ...
|
---|
[254] | 625 | const PertialSchedule *pTempPertialSchedule = compiler.codeGenerator.op_jmp( 0, sizeof(long), true );
|
---|
[3] | 626 |
|
---|
| 627 | //レキシカルスコープをレベルダウン
|
---|
[254] | 628 | compiler.codeGenerator.lexicalScopes.End();
|
---|
[3] | 629 |
|
---|
[243] | 630 | //jmpジャンプ先のオフセット値
|
---|
| 631 | compiler.codeGenerator.opfix_JmpPertialSchedule( pTempPertialSchedule );
|
---|
[3] | 632 |
|
---|
| 633 | //Continueアドレスを復元
|
---|
[242] | 634 | compiler.codeGenerator.ContinueAreaEnd();
|
---|
[3] | 635 | }
|
---|
| 636 | void OpcodeContinue(void){
|
---|
| 637 | //jmp ...(Continue addr)
|
---|
[242] | 638 | compiler.codeGenerator.op_jmp_continue();
|
---|
[3] | 639 | }
|
---|
| 640 |
|
---|
| 641 | void OpcodeExitSub(void){
|
---|
[75] | 642 | if( UserProc::IsGlobalAreaCompiling() ){
|
---|
[3] | 643 | SetError(12,"Exit Sub/Function",cp);
|
---|
| 644 | return;
|
---|
| 645 | }
|
---|
| 646 |
|
---|
[34] | 647 | //未解放のローカルオブジェクトのデストラクタを呼び出す
|
---|
[254] | 648 | compiler.codeGenerator.lexicalScopes.CallDestructorsOfReturn();
|
---|
[34] | 649 |
|
---|
[3] | 650 | //jmp ...(End Sub/Function)
|
---|
[254] | 651 | compiler.codeGenerator.op_jmp_exitsub();
|
---|
| 652 | }
|
---|
[3] | 653 |
|
---|
[254] | 654 | //Caseスケジュール
|
---|
| 655 | class SelectSchedule
|
---|
| 656 | {
|
---|
| 657 | public:
|
---|
| 658 | SelectSchedule( int typeSize )
|
---|
| 659 | : typeSize( typeSize )
|
---|
| 660 | , nowCaseSchedule( 0 )
|
---|
| 661 | {
|
---|
| 662 | }
|
---|
[3] | 663 |
|
---|
[254] | 664 | PertialSchedules casePertialSchedules;
|
---|
| 665 | int typeSize;
|
---|
| 666 | int nowCaseSchedule;
|
---|
| 667 | };
|
---|
| 668 | std::vector<SelectSchedule> selectSchedules;
|
---|
[3] | 669 |
|
---|
[75] | 670 | void OpcodeSelect( const char *lpszParms ){
|
---|
[3] | 671 | extern HANDLE hHeap;
|
---|
| 672 | extern char *basbuf;
|
---|
| 673 | int i,i2,i3,NowCaseCp;
|
---|
| 674 | char temporary[VN_SIZE];
|
---|
[254] | 675 |
|
---|
[75] | 676 | int reg1=REG_RAX;
|
---|
| 677 | Type type1;
|
---|
| 678 | if( !NumOpe(®1,lpszParms,Type(), type1 ) ){
|
---|
| 679 | return;
|
---|
| 680 | }
|
---|
[3] | 681 |
|
---|
[254] | 682 | selectSchedules.push_back( SelectSchedule( type1.GetSize() ) );
|
---|
| 683 |
|
---|
| 684 | if( selectSchedules.back().typeSize < sizeof(long) ){
|
---|
| 685 | selectSchedules.back().typeSize = sizeof(long);
|
---|
| 686 | }
|
---|
| 687 |
|
---|
[75] | 688 | if(type1.IsDouble()){
|
---|
[3] | 689 | //movsd qword ptr[rsp+offset],xmm_reg ※スタックフレームを利用
|
---|
| 690 | pobj_sf->push(reg1,sizeof(double));
|
---|
| 691 | }
|
---|
[75] | 692 | else if(type1.IsSingle()){
|
---|
[3] | 693 | //movss dword ptr[rsp+offset],xmm_reg ※スタックフレームを利用
|
---|
| 694 | pobj_sf->push(reg1,sizeof(float));
|
---|
| 695 | }
|
---|
| 696 | else{
|
---|
[75] | 697 | ExtendTypeTo64(type1.GetBasicType(),reg1);
|
---|
[3] | 698 |
|
---|
| 699 | //mov qword ptr[rsp+offset],reg ※スタックフレームを利用
|
---|
| 700 | pobj_sf->push(reg1);
|
---|
| 701 | }
|
---|
| 702 |
|
---|
| 703 | for(i=cp;;i++){
|
---|
| 704 | if(basbuf[i]=='\0'){
|
---|
[254] | 705 | selectSchedules.pop_back();
|
---|
[3] | 706 | SetError(22,"Select",cp);
|
---|
| 707 | return;
|
---|
| 708 | }
|
---|
| 709 | if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE){
|
---|
| 710 | for(i2=0;;i++){
|
---|
| 711 | if(basbuf[i]==1&&basbuf[i+1]==ESC_SELECTCASE) i2++;
|
---|
| 712 | if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT){
|
---|
| 713 | i2--;
|
---|
| 714 | if(i2==0) break;
|
---|
| 715 | }
|
---|
| 716 | }
|
---|
| 717 | continue;
|
---|
| 718 | }
|
---|
| 719 | if(basbuf[i]==1&&basbuf[i+1]==ESC_ENDSELECT) break;
|
---|
| 720 |
|
---|
| 721 | if(basbuf[i]==1&&basbuf[i+1]==ESC_CASE){
|
---|
| 722 | NowCaseCp=i;
|
---|
| 723 |
|
---|
| 724 | i++;
|
---|
| 725 | while(1){
|
---|
| 726 | for(i++,i2=0;;i++,i2++){
|
---|
| 727 | if(basbuf[i]=='\"'){
|
---|
| 728 | i3=GetStringInQuotation(temporary+i2,basbuf+i);
|
---|
| 729 | i+=i3-1;
|
---|
| 730 | i2+=i3-1;
|
---|
| 731 | continue;
|
---|
| 732 | }
|
---|
| 733 | if(basbuf[i]=='('){
|
---|
| 734 | i3=GetStringInPare(temporary+i2,basbuf+i);
|
---|
| 735 | i+=i3-1;
|
---|
| 736 | i2+=i3-1;
|
---|
| 737 | continue;
|
---|
| 738 | }
|
---|
| 739 | if(basbuf[i]=='['){
|
---|
| 740 | i3=GetStringInBracket(temporary+i2,basbuf+i);
|
---|
| 741 | i+=i3-1;
|
---|
| 742 | i2+=i3-1;
|
---|
| 743 | continue;
|
---|
| 744 | }
|
---|
| 745 |
|
---|
| 746 | if(IsCommandDelimitation(basbuf[i])){
|
---|
| 747 | temporary[i2]=0;
|
---|
| 748 | break;
|
---|
| 749 | }
|
---|
| 750 | if(basbuf[i]==','){
|
---|
| 751 | temporary[i2]=0;
|
---|
| 752 | break;
|
---|
| 753 | }
|
---|
| 754 |
|
---|
| 755 | temporary[i2]=basbuf[i];
|
---|
| 756 | }
|
---|
| 757 |
|
---|
| 758 | //エラー用
|
---|
| 759 | i2=cp;
|
---|
| 760 | cp=NowCaseCp;
|
---|
| 761 |
|
---|
[75] | 762 | int reg2=REG_RDX;
|
---|
| 763 | Type type2;
|
---|
| 764 | if( !NumOpe(®2,temporary,type1,type2) ){
|
---|
| 765 | return;
|
---|
| 766 | }
|
---|
[3] | 767 |
|
---|
| 768 | cp=i2;
|
---|
| 769 |
|
---|
[75] | 770 | if(type1.IsObject()){
|
---|
[206] | 771 | std::vector<const UserProc *> subs;
|
---|
[345] | 772 | type1.GetClass().GetDynamicMethods().Enum( CALC_EQUAL, subs );
|
---|
[50] | 773 | if( subs.size() == 0 ){
|
---|
[3] | 774 | return;
|
---|
| 775 | }
|
---|
| 776 |
|
---|
[75] | 777 | Parameters params;
|
---|
| 778 | params.push_back( new Parameter( "", Type( type2 ) ) );
|
---|
[3] | 779 |
|
---|
| 780 | //オーバーロードを解決
|
---|
[206] | 781 | const UserProc *pUserProc = OverloadSolution("==",subs, params, NULL);
|
---|
[3] | 782 |
|
---|
[75] | 783 | delete params[0];
|
---|
| 784 |
|
---|
| 785 | if(!pUserProc){
|
---|
[3] | 786 | //エラー
|
---|
| 787 | return;
|
---|
| 788 | }
|
---|
| 789 |
|
---|
| 790 |
|
---|
| 791 | //実体オブジェクト
|
---|
| 792 | if(reg2!=REG_RDX){
|
---|
| 793 | //mov rdx,reg2
|
---|
[226] | 794 | compiler.codeGenerator.op_mov_RR(REG_RDX,reg2);
|
---|
[3] | 795 | }
|
---|
| 796 |
|
---|
| 797 | //mov rcx,qword ptr[rsp+offset] ※スタックフレームから参照
|
---|
| 798 | pobj_sf->ref(REG_RCX);
|
---|
| 799 |
|
---|
| 800 | //call operator_proc ※ ==演算子
|
---|
[226] | 801 | compiler.codeGenerator.op_call(pUserProc);
|
---|
[3] | 802 |
|
---|
| 803 | //test rax,rax
|
---|
[226] | 804 | compiler.codeGenerator.op_test(REG_RAX,REG_RAX);
|
---|
[3] | 805 |
|
---|
| 806 | //jne ...
|
---|
[254] | 807 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
| 808 | compiler.codeGenerator.op_jne( 0, sizeof(long), true )
|
---|
| 809 | );
|
---|
[3] | 810 | }
|
---|
| 811 | else{
|
---|
[75] | 812 | if(type1.IsDouble()){
|
---|
[3] | 813 | int xmm_reg;
|
---|
| 814 | if(IsXmmReg(reg2)) xmm_reg=reg2;
|
---|
| 815 | else xmm_reg=REG_XMM5;
|
---|
[75] | 816 | ChangeTypeToXmm_Double(type2.GetBasicType(),xmm_reg,reg2);
|
---|
[3] | 817 |
|
---|
| 818 | //movsd xmm4,qword ptr[rsp+offset] ※スタックフレームから参照
|
---|
| 819 | pobj_sf->ref(REG_XMM4,sizeof(double));
|
---|
| 820 |
|
---|
| 821 | //comiss xmm_reg1,xmm_reg2
|
---|
[226] | 822 | compiler.codeGenerator.op_comisd(xmm_reg,REG_XMM4);
|
---|
[3] | 823 | }
|
---|
[75] | 824 | else if(type1.IsSingle()){
|
---|
[3] | 825 | int xmm_reg;
|
---|
| 826 | if(IsXmmReg(reg2)) xmm_reg=reg2;
|
---|
| 827 | else xmm_reg=REG_XMM5;
|
---|
[75] | 828 | ChangeTypeToXmm_Single(type2.GetBasicType(),xmm_reg,reg2);
|
---|
[3] | 829 |
|
---|
| 830 | //movss xmm4,dword ptr[rsp+offset] ※スタックフレームから参照
|
---|
| 831 | pobj_sf->ref(REG_XMM4,sizeof(float));
|
---|
| 832 |
|
---|
| 833 | //comiss xmm_reg1,xmm_reg2
|
---|
[226] | 834 | compiler.codeGenerator.op_comiss(xmm_reg,REG_XMM4);
|
---|
[3] | 835 | }
|
---|
| 836 | else{
|
---|
| 837 | //その他整数型
|
---|
| 838 |
|
---|
[75] | 839 | i2=NeutralizationType(type1.GetBasicType(),-1,type2.GetBasicType(),-1);
|
---|
[3] | 840 |
|
---|
| 841 | //mov r14,qword ptr[rsp+offset] ※スタックフレームから参照
|
---|
| 842 | pobj_sf->ref(REG_R14);
|
---|
| 843 |
|
---|
| 844 | //cmp reg2,r14
|
---|
[308] | 845 | compiler.codeGenerator.op_cmp_reg(Type(i2).GetSize(),reg2,REG_R14);
|
---|
[3] | 846 | }
|
---|
| 847 |
|
---|
| 848 | //je ...
|
---|
[254] | 849 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
| 850 | compiler.codeGenerator.op_je( 0, sizeof(long), true )
|
---|
| 851 | );
|
---|
[3] | 852 | }
|
---|
| 853 |
|
---|
| 854 | if(basbuf[i]!=',') break;
|
---|
| 855 | }
|
---|
| 856 | }
|
---|
| 857 | if(basbuf[i]==1&&basbuf[i+1]==ESC_CASEELSE){
|
---|
| 858 | //jmp ...
|
---|
[254] | 859 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
| 860 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
|
---|
| 861 | );
|
---|
[3] | 862 | }
|
---|
| 863 | }
|
---|
| 864 |
|
---|
| 865 | //スタックフレームを1スペースだけ解除
|
---|
| 866 | pobj_sf->pop(REG_NON);
|
---|
| 867 |
|
---|
| 868 | //レキシカルスコープをレベルアップ
|
---|
[308] | 869 | compiler.codeGenerator.lexicalScopes.Start( compiler.codeGenerator.GetNativeCodeSize(), LexicalScope::SCOPE_TYPE_SELECT );
|
---|
[3] | 870 |
|
---|
| 871 | //Select Case内をコンパイル
|
---|
| 872 | CompileBuffer(ESC_ENDSELECT,0);
|
---|
| 873 |
|
---|
| 874 | //jmp EndSelect
|
---|
[254] | 875 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
| 876 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
|
---|
| 877 | );
|
---|
[3] | 878 |
|
---|
| 879 | //最終スケジュール
|
---|
[254] | 880 | for(i=selectSchedules.back().nowCaseSchedule;i<(int)selectSchedules.back().casePertialSchedules.size();i++){
|
---|
| 881 | compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[i] );
|
---|
[3] | 882 | }
|
---|
| 883 |
|
---|
| 884 | //レキシカルスコープをレベルダウン
|
---|
[254] | 885 | compiler.codeGenerator.lexicalScopes.End();
|
---|
[3] | 886 |
|
---|
[254] | 887 | selectSchedules.pop_back();
|
---|
[3] | 888 | }
|
---|
| 889 | void OpcodeCase(char *Parameter){
|
---|
| 890 | int i;
|
---|
| 891 |
|
---|
[254] | 892 | if(selectSchedules.back().typeSize==-1){
|
---|
[3] | 893 | SetError(30,"Case",cp);
|
---|
| 894 | return;
|
---|
| 895 | }
|
---|
| 896 |
|
---|
| 897 | //jmp EndSelect
|
---|
[254] | 898 | selectSchedules.back().casePertialSchedules.push_back(
|
---|
| 899 | compiler.codeGenerator.op_jmp( 0, sizeof(long), true )
|
---|
| 900 | );
|
---|
[3] | 901 |
|
---|
| 902 | i=0;
|
---|
| 903 | while(1){
|
---|
| 904 | //Caseスケジュール
|
---|
[254] | 905 | compiler.codeGenerator.opfix_JmpPertialSchedule( selectSchedules.back().casePertialSchedules[selectSchedules.back().nowCaseSchedule] );
|
---|
| 906 | selectSchedules.back().nowCaseSchedule++;
|
---|
[3] | 907 |
|
---|
| 908 | i=JumpOneParameter(Parameter,i);
|
---|
| 909 | if(Parameter[i]=='\0') break;
|
---|
| 910 | }
|
---|
| 911 | }
|
---|
| 912 |
|
---|
| 913 | void OpcodeGosub(char *Parameter){
|
---|
| 914 | SetError(-1,"Gosub ~ Returnステートメントは64ビットコンパイラで利用することはできません。",cp);
|
---|
| 915 | }
|
---|
| 916 | void OpcodeReturn(char *Parameter){
|
---|
[75] | 917 | if( UserProc::IsGlobalAreaCompiling() ){
|
---|
[34] | 918 | SetError(62,NULL,cp);
|
---|
[3] | 919 | }
|
---|
| 920 | else{
|
---|
| 921 | //戻り値をセット
|
---|
| 922 | if(Parameter[0]){
|
---|
[206] | 923 | const UserProc &proc = UserProc::CompilingUserProc();
|
---|
[3] | 924 |
|
---|
[75] | 925 | const char *temp = "_System_ReturnValue";
|
---|
| 926 | if(proc.GetName()[0]==1&&proc.GetName()[1]==ESC_OPERATOR)
|
---|
| 927 | {
|
---|
[40] | 928 | }
|
---|
| 929 | else{
|
---|
[75] | 930 | temp=proc.GetName().c_str();
|
---|
| 931 | }
|
---|
| 932 |
|
---|
| 933 | char temporary[VN_SIZE];
|
---|
| 934 | sprintf(temporary,"%s=%s",temp,Parameter);
|
---|
| 935 | OpcodeCalc(temporary);
|
---|
[3] | 936 | }
|
---|
| 937 |
|
---|
| 938 | //プロシージャを抜け出す(C言語のreturnと同様の処理を行う)
|
---|
| 939 | OpcodeExitSub();
|
---|
| 940 | }
|
---|
| 941 | }
|
---|
| 942 |
|
---|
| 943 |
|
---|
| 944 | ////////////
|
---|
| 945 | // ポインタ
|
---|
| 946 | ////////////
|
---|
| 947 |
|
---|
| 948 | void OpcodeSetPtrData(char *Parameter,int type){
|
---|
[75] | 949 | int i;
|
---|
[3] | 950 | char temporary[VN_SIZE];
|
---|
| 951 |
|
---|
| 952 | if(Parameter[0]=='('){
|
---|
| 953 | i=JumpStringInPare(Parameter,1);
|
---|
| 954 | if(Parameter[i+1]=='\0'){
|
---|
| 955 | for(i=0;;i++){
|
---|
| 956 | Parameter[i]=Parameter[i+1];
|
---|
| 957 | if(Parameter[i]=='\0') break;
|
---|
| 958 | }
|
---|
| 959 | Parameter[i-1]=0;
|
---|
| 960 | }
|
---|
| 961 | }
|
---|
| 962 |
|
---|
| 963 | //第1パラメータを取得
|
---|
| 964 | i=GetOneParameter(Parameter,0,temporary);
|
---|
| 965 | if(!Parameter[i]){
|
---|
| 966 | SetError(1,NULL,cp);
|
---|
| 967 | return;
|
---|
| 968 | }
|
---|
| 969 |
|
---|
| 970 | int reg_ptr=REG_RAX;
|
---|
[75] | 971 | Type resultType;
|
---|
| 972 | if( !NumOpe(®_ptr,temporary,Type(),resultType) ){
|
---|
| 973 | return;
|
---|
| 974 | }
|
---|
| 975 | if(!resultType.IsWhole()){
|
---|
[3] | 976 | SetError(11,Parameter,cp);
|
---|
| 977 | return;
|
---|
| 978 | }
|
---|
| 979 |
|
---|
| 980 | //結果を格納しているレジスタをブロッキング
|
---|
| 981 | pobj_BlockReg->lock(reg_ptr);
|
---|
| 982 |
|
---|
| 983 | //第2パラメータを取得
|
---|
| 984 | i=GetOneParameter(Parameter,i,temporary);
|
---|
| 985 | if(Parameter[i]){
|
---|
| 986 | SetError(1,NULL,cp);
|
---|
| 987 | return;
|
---|
| 988 | }
|
---|
| 989 |
|
---|
| 990 | int temp_reg=REG_NON;
|
---|
[75] | 991 | if( !NumOpe(&temp_reg,temporary,Type(),resultType) ){
|
---|
| 992 | return;
|
---|
| 993 | }
|
---|
[3] | 994 |
|
---|
| 995 | //レジスタのブロッキングを解除
|
---|
| 996 | pobj_BlockReg->clear();
|
---|
| 997 |
|
---|
| 998 | if(type==DEF_DOUBLE){
|
---|
[75] | 999 | ChangeTypeToXmm_Double(resultType.GetBasicType(),REG_XMM0,temp_reg);
|
---|
[3] | 1000 |
|
---|
| 1001 | //movsd qword ptr[reg_ptr],xmm0
|
---|
[226] | 1002 | compiler.codeGenerator.op_movsd_MR(REG_XMM0,reg_ptr,0,MOD_BASE);
|
---|
[3] | 1003 | }
|
---|
| 1004 | else if(type==DEF_SINGLE){
|
---|
[75] | 1005 | ChangeTypeToXmm_Single(resultType.GetBasicType(),REG_XMM0,temp_reg);
|
---|
[3] | 1006 |
|
---|
| 1007 | //movss dword ptr[reg_ptr],xmm0
|
---|
[226] | 1008 | compiler.codeGenerator.op_movss_MR(REG_XMM0,reg_ptr,0,MOD_BASE);
|
---|
[3] | 1009 | }
|
---|
| 1010 | else{
|
---|
[308] | 1011 | ChangeTypeToWhole(resultType,Type(type),REG_RCX,temp_reg);
|
---|
[3] | 1012 |
|
---|
| 1013 | //mov ptr[reg_ptr],rcx
|
---|
[308] | 1014 | compiler.codeGenerator.op_mov_MR(Type(type).GetSize(),REG_RCX,reg_ptr,0,MOD_BASE);
|
---|
[3] | 1015 | }
|
---|
| 1016 | }
|
---|