[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[182] | 3 | #include <jenga/include/smoothie/Smoothie.h>
|
---|
| 4 | #include <jenga/include/smoothie/SmoothieException.h>
|
---|
| 5 |
|
---|
[248] | 6 | #include <LexicalScope.h>
|
---|
[182] | 7 | #include <CodeGenerator.h>
|
---|
[193] | 8 | #include <Compiler.h>
|
---|
[195] | 9 | #include <NamespaceSupporter.h>
|
---|
[182] | 10 |
|
---|
[4] | 11 | #include "../BasicCompiler_Common/common.h"
|
---|
| 12 |
|
---|
| 13 | #ifdef _AMD64_
|
---|
| 14 | #include "../BasicCompiler64/opcode.h"
|
---|
| 15 | #else
|
---|
[5] | 16 | #include "../BasicCompiler32/opcode.h"
|
---|
[4] | 17 | #endif
|
---|
| 18 |
|
---|
[182] | 19 | #include <Exception.h>
|
---|
| 20 |
|
---|
[4] | 21 | //With情報
|
---|
| 22 | WITHINFO WithInfo;
|
---|
| 23 |
|
---|
[263] | 24 | //デバッグ用行番号情報
|
---|
| 25 | SourceLines oldSourceLines;
|
---|
[4] | 26 |
|
---|
[89] | 27 |
|
---|
[263] | 28 |
|
---|
[16] | 29 | ///////////////////////////////////////////////////
|
---|
[17] | 30 | // トークンを取得
|
---|
| 31 | ///////////////////////////////////////////////////
|
---|
[296] | 32 | void GetIdentifierToken( char *token, const char *source, int &pos )
|
---|
| 33 | {
|
---|
[17] | 34 | for( int i=0; ; i++, pos++ ){
|
---|
| 35 | if( ! IsVariableChar( source[pos] ) ){
|
---|
| 36 | token[i] = 0;
|
---|
| 37 | break;
|
---|
| 38 | }
|
---|
| 39 | token[i] = source[pos];
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
[296] | 42 | void GetCommandToken( char *token, const char *source, int &pos )
|
---|
| 43 | {
|
---|
| 44 | for( int i=0; ; i++, pos++ ){
|
---|
| 45 | if( IsCommandDelimitation( source[pos] ) ){
|
---|
| 46 | token[i] = 0;
|
---|
| 47 | break;
|
---|
| 48 | }
|
---|
| 49 | token[i] = source[pos];
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
[381] | 52 | void GetCustomToken( char *token, const char *source, int &pos, char delimitation, bool isEscapeSequence )
|
---|
| 53 | {
|
---|
| 54 | for( int i=0; ; i++, pos++ ){
|
---|
| 55 | if( isEscapeSequence )
|
---|
| 56 | {
|
---|
| 57 | if( source[pos] == 1 && source[pos+1] == delimitation )
|
---|
| 58 | {
|
---|
| 59 | token[i] = 0;
|
---|
| 60 | pos++;
|
---|
| 61 | break;
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | else
|
---|
| 65 | {
|
---|
| 66 | if( source[pos] == delimitation )
|
---|
| 67 | {
|
---|
| 68 | token[i] = 0;
|
---|
| 69 | break;
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
[17] | 72 |
|
---|
[381] | 73 | token[i] = source[pos];
|
---|
[17] | 74 |
|
---|
[381] | 75 | if( source[pos] == '\0' )
|
---|
| 76 | {
|
---|
| 77 | break;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
[17] | 83 | ///////////////////////////////////////////////////
|
---|
[296] | 84 | // ジェネリクスのクラス型記述を分析
|
---|
| 85 | ///////////////////////////////////////////////////
|
---|
[299] | 86 | void SplitGenericClassInstance( const char *fullName, char *className, Jenga::Common::Strings &typeParameters )
|
---|
[296] | 87 | {
|
---|
| 88 | int i = 0;
|
---|
| 89 | typeParameters.clear();
|
---|
| 90 |
|
---|
| 91 | //クラス名を取得
|
---|
| 92 | GetIdentifierToken( className, fullName, i );
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | /////////////////////////////////////////////////////////
|
---|
| 96 | // ☆★☆ ジェネリクスサポート ☆★☆
|
---|
| 97 | if( fullName[i] == '<' )
|
---|
| 98 | {
|
---|
| 99 | while( true )
|
---|
| 100 | {
|
---|
| 101 | i++;
|
---|
| 102 |
|
---|
| 103 | // 型パラメータを取得
|
---|
| 104 | char temporary[VN_SIZE];
|
---|
| 105 | GetIdentifierToken( temporary, fullName, i );
|
---|
| 106 | if( temporary[0] == '\0' )
|
---|
| 107 | {
|
---|
| 108 | extern int cp;
|
---|
| 109 | SetError(1,NULL,cp);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | typeParameters.push_back( temporary );
|
---|
| 113 |
|
---|
| 114 | if( fullName[i] == ',' )
|
---|
| 115 | {
|
---|
| 116 | continue;
|
---|
| 117 | }
|
---|
| 118 | else if( fullName[i] == '>' )
|
---|
| 119 | {
|
---|
| 120 | break;
|
---|
| 121 | }
|
---|
| 122 | else
|
---|
| 123 | {
|
---|
| 124 | extern int cp;
|
---|
| 125 | SetError(1,NULL,cp);
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 | /////////////////////////////////////////////////////////
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 | ///////////////////////////////////////////////////
|
---|
[16] | 134 | // 対になっているステートメントを飛び越す
|
---|
| 135 | // ※グローバル領域用
|
---|
| 136 | ///////////////////////////////////////////////////
|
---|
| 137 | int JumpStatement(const char *source, int &pos){
|
---|
| 138 | if( source[pos] != 1 ) return 0;
|
---|
| 139 |
|
---|
| 140 | if( ! IsCommandDelimitation( source[pos - 1] ) ){
|
---|
| 141 | //直前がコマンド区切りではない場合
|
---|
| 142 | return 0;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | char cStatement = source[pos + 1];
|
---|
| 146 |
|
---|
| 147 | char cEnd = GetEndXXXCommand( cStatement );
|
---|
| 148 | if( cEnd == 0 ) return 0;
|
---|
| 149 |
|
---|
| 150 | pos += 2;
|
---|
| 151 | while( ! ( source[pos] == 1 && source[pos + 1] == cEnd ) ){
|
---|
| 152 |
|
---|
| 153 | if( source[pos] == '\0' ){
|
---|
| 154 | char temporary[64];
|
---|
| 155 | GetDefaultNameFromES( cStatement, temporary );
|
---|
| 156 | SetError( 22, temporary, pos );
|
---|
| 157 | return -1;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | pos++;
|
---|
| 161 | }
|
---|
| 162 | if( ! ( source[pos] == '\0' || source[pos + 2] == '\0' ) ){
|
---|
| 163 | pos += 2;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | return 1;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
[372] | 169 | void Compile( const char *source )
|
---|
| 170 | {
|
---|
| 171 | char *temporary = (char *)malloc( lstrlen( source ) + 8192 );
|
---|
| 172 | lstrcpy( temporary, source );
|
---|
| 173 | int backCp = cp;
|
---|
| 174 | MakeMiddleCode( temporary );
|
---|
| 175 | ChangeOpcode( temporary );
|
---|
| 176 | cp = backCp;
|
---|
| 177 | free( temporary );
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[4] | 180 | void ChangeOpcode(char *Command){
|
---|
| 181 | extern HANDLE hHeap;
|
---|
| 182 |
|
---|
[206] | 183 | if(Command[0]=='\0')
|
---|
| 184 | {
|
---|
| 185 | return;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | trace_for_sourcecodestep( FormatEscapeSequenceStringToDefaultString(Command) );
|
---|
| 189 |
|
---|
[4] | 190 | if(Command[0]=='*'&&IsVariableTopChar(Command[1])){
|
---|
| 191 | //Goto先ラベル
|
---|
[276] | 192 | compiler.codeGenerator.gotoLabels.push_back( GotoLabel( Command + 1, compiler.codeGenerator.GetNativeCodeSize() ) );
|
---|
[4] | 193 |
|
---|
| 194 | //書き込みスケジュール
|
---|
[253] | 195 | GotoLabelSchedules::iterator it = compiler.codeGenerator.gotoLabelSchedules.begin();
|
---|
[246] | 196 | while( it != compiler.codeGenerator.gotoLabelSchedules.end() )
|
---|
| 197 | {
|
---|
[253] | 198 | if( (*it)->GetName() == Command+1 )
|
---|
[246] | 199 | {
|
---|
[253] | 200 | compiler.codeGenerator.opfix_JmpPertialSchedule( (*it) );
|
---|
[246] | 201 |
|
---|
[4] | 202 | //詰める
|
---|
[246] | 203 | it = compiler.codeGenerator.gotoLabelSchedules.erase( it );
|
---|
[4] | 204 | }
|
---|
[246] | 205 | else
|
---|
| 206 | {
|
---|
| 207 | it++;
|
---|
| 208 | }
|
---|
[4] | 209 | }
|
---|
| 210 | return;
|
---|
| 211 | }
|
---|
| 212 | if(Command[0]==1){
|
---|
| 213 | switch(Command[1]){
|
---|
| 214 | case ESC_CONST:
|
---|
[7] | 215 | OpcodeDim(Command+2, DIMFLAG_CONST);
|
---|
| 216 | break;
|
---|
| 217 |
|
---|
[4] | 218 | case ESC_TYPEDEF:
|
---|
[113] | 219 | if( UserProc::IsLocalAreaCompiling() ){
|
---|
| 220 | // ローカル領域をコンパイルしているとき
|
---|
| 221 | SetError(65,"TypeDef",cp );
|
---|
| 222 | }
|
---|
| 223 |
|
---|
[78] | 224 | //既に収集済み
|
---|
[4] | 225 | break;
|
---|
| 226 |
|
---|
[322] | 227 | case ESC_DELEGATE:
|
---|
| 228 | if( UserProc::IsLocalAreaCompiling() ){
|
---|
| 229 | // ローカル領域をコンパイルしているとき
|
---|
| 230 | SetError(65,"Delegate",cp );
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | //既に収集済み
|
---|
| 234 | break;
|
---|
| 235 |
|
---|
[4] | 236 | case ESC_STATIC:
|
---|
| 237 | OpcodeDim(Command+2,DIMFLAG_STATIC);
|
---|
| 238 | break;
|
---|
| 239 |
|
---|
| 240 | case ESC_IF:
|
---|
| 241 | OpcodeIf(Command+2);
|
---|
| 242 | break;
|
---|
| 243 | case ESC_EXITWHILE:
|
---|
[182] | 244 | {
|
---|
[248] | 245 | LexicalScope *pScope = compiler.codeGenerator.lexicalScopes.SearchScope( LexicalScope::SCOPE_TYPE_WHILE );
|
---|
[182] | 246 | if( !pScope ){
|
---|
| 247 | SetError(12,"Exit While",cp);
|
---|
| 248 | return;
|
---|
| 249 | }
|
---|
| 250 | pScope->Break();
|
---|
| 251 | }
|
---|
[4] | 252 | break;
|
---|
| 253 | case ESC_EXITFOR:
|
---|
[182] | 254 | {
|
---|
[248] | 255 | LexicalScope *pScope = compiler.codeGenerator.lexicalScopes.SearchScope( LexicalScope::SCOPE_TYPE_FOR );
|
---|
[182] | 256 | if( !pScope ){
|
---|
| 257 | SetError(12,"Exit For",cp);
|
---|
| 258 | return;
|
---|
| 259 | }
|
---|
| 260 | pScope->Break();
|
---|
| 261 | }
|
---|
[4] | 262 | break;
|
---|
| 263 | case ESC_EXITDO:
|
---|
[182] | 264 | {
|
---|
[248] | 265 | LexicalScope *pScope = compiler.codeGenerator.lexicalScopes.SearchScope( LexicalScope::SCOPE_TYPE_DO );
|
---|
[182] | 266 | if( !pScope ){
|
---|
| 267 | SetError(12,"Exit Do",cp);
|
---|
| 268 | return;
|
---|
| 269 | }
|
---|
| 270 | pScope->Break();
|
---|
| 271 | }
|
---|
[4] | 272 | break;
|
---|
| 273 | case ESC_CONTINUE:
|
---|
| 274 | OpcodeContinue();
|
---|
| 275 | break;
|
---|
| 276 |
|
---|
| 277 | case ESC_EXITSUB:
|
---|
| 278 | case ESC_EXITFUNCTION:
|
---|
| 279 | case ESC_EXITMACRO:
|
---|
| 280 | OpcodeExitSub();
|
---|
| 281 | break;
|
---|
| 282 |
|
---|
| 283 | case ESC_SELECTCASE:
|
---|
| 284 | OpcodeSelect(Command+2);
|
---|
| 285 | break;
|
---|
| 286 | case ESC_CASE:
|
---|
| 287 | case ESC_CASEELSE:
|
---|
| 288 | OpcodeCase(Command+2);
|
---|
| 289 | break;
|
---|
| 290 |
|
---|
| 291 | case ESC_WITH:
|
---|
| 292 | extern WITHINFO WithInfo;
|
---|
| 293 |
|
---|
| 294 | WithInfo.ppName=(char **)HeapReAlloc(hHeap,0,WithInfo.ppName,(WithInfo.num+1)*sizeof(char **));
|
---|
| 295 | WithInfo.ppName[WithInfo.num]=(char *)HeapAlloc(hHeap,0,lstrlen(Command+2)+1);
|
---|
| 296 | lstrcpy(WithInfo.ppName[WithInfo.num],Command+2);
|
---|
| 297 |
|
---|
| 298 | WithInfo.pWithCp=(int *)HeapReAlloc(hHeap,0,WithInfo.pWithCp,(WithInfo.num+1)*sizeof(int));
|
---|
| 299 | WithInfo.pWithCp[WithInfo.num]=cp;
|
---|
| 300 |
|
---|
| 301 | WithInfo.num++;
|
---|
| 302 | break;
|
---|
| 303 | case ESC_ENDWITH:
|
---|
| 304 | if(WithInfo.num<=0){
|
---|
| 305 | SetError(12,"End With",cp);
|
---|
| 306 | return;
|
---|
| 307 | }
|
---|
| 308 | WithInfo.num--;
|
---|
| 309 | HeapDefaultFree(WithInfo.ppName[WithInfo.num]);
|
---|
| 310 | break;
|
---|
| 311 | case ESC_DECLARE:
|
---|
[113] | 312 | if( UserProc::IsLocalAreaCompiling() ){
|
---|
| 313 | // ローカル領域をコンパイルしているとき
|
---|
| 314 | SetError(65,"Declare",cp );
|
---|
| 315 | }
|
---|
[4] | 316 | break;
|
---|
[26] | 317 |
|
---|
[99] | 318 | case ESC_NAMESPACE:
|
---|
[199] | 319 | compiler.GetNamespaceSupporter().GetLivingNamespaceScopes().push_back( Command + 2 );
|
---|
[103] | 320 | break;
|
---|
[99] | 321 | case ESC_ENDNAMESPACE:
|
---|
[199] | 322 | if( compiler.GetNamespaceSupporter().GetLivingNamespaceScopes().size() <= 0 ){
|
---|
[103] | 323 | SetError(12,"End Namespace",cp);
|
---|
| 324 | }
|
---|
[199] | 325 | compiler.GetNamespaceSupporter().GetLivingNamespaceScopes().pop_back();
|
---|
[99] | 326 | break;
|
---|
[107] | 327 | case ESC_IMPORTS:
|
---|
[199] | 328 | compiler.GetNamespaceSupporter().ImportsNamespace( Command + 2 );
|
---|
[107] | 329 | break;
|
---|
| 330 | case ESC_CLEARNAMESPACEIMPORTED:
|
---|
[199] | 331 | compiler.GetNamespaceSupporter().GetImportedNamespaces().clear();
|
---|
[107] | 332 | break;
|
---|
[99] | 333 |
|
---|
[26] | 334 | //Tryによる例外処理
|
---|
| 335 | case ESC_TRY:
|
---|
| 336 | Exception::TryCommand();
|
---|
| 337 | break;
|
---|
| 338 | case ESC_CATCH:
|
---|
[359] | 339 | Exception::CatchCommand( Command + 2 );
|
---|
[26] | 340 | break;
|
---|
| 341 | case ESC_FINALLY:
|
---|
| 342 | Exception::FinallyCommand();
|
---|
| 343 | break;
|
---|
| 344 | case ESC_ENDTRY:
|
---|
| 345 | Exception::EndTryCommand();
|
---|
| 346 | break;
|
---|
| 347 | case ESC_THROW:
|
---|
| 348 | Exception::ThrowCommand( Command + 2 );
|
---|
| 349 | break;
|
---|
| 350 |
|
---|
[4] | 351 | default:
|
---|
| 352 | char temporary[64];
|
---|
| 353 | GetDefaultNameFromES(Command[1],temporary);
|
---|
| 354 | SetError(30,temporary,cp);
|
---|
| 355 | break;
|
---|
| 356 | }
|
---|
| 357 | return;
|
---|
| 358 | }
|
---|
| 359 | switch(MAKEWORD(Command[1],Command[0])){
|
---|
| 360 | case COM_DIM:
|
---|
| 361 | OpcodeDim(Command+2,0);
|
---|
| 362 | break;
|
---|
| 363 | case COM_DELETE:
|
---|
[64] | 364 | OpcodeDelete(Command+2, false);
|
---|
[4] | 365 | break;
|
---|
[64] | 366 | case COM_SWEEPINGDELETE:
|
---|
| 367 | OpcodeDelete(Command+2, true);
|
---|
| 368 | break;
|
---|
[4] | 369 |
|
---|
| 370 | case COM_GOTO:
|
---|
| 371 | OpcodeGoto(Command+2);
|
---|
| 372 | break;
|
---|
| 373 | case COM_WHILE:
|
---|
| 374 | OpcodeWhile(Command+2);
|
---|
| 375 | break;
|
---|
| 376 | case COM_FOR:
|
---|
| 377 | OpcodeFor(Command+2);
|
---|
| 378 | break;
|
---|
[372] | 379 | case COM_FOREACH:
|
---|
| 380 | OpcodeForeach(Command+2);
|
---|
| 381 | break;
|
---|
[4] | 382 | case COM_DO:
|
---|
| 383 | OpcodeDo(Command+2);
|
---|
| 384 | break;
|
---|
| 385 |
|
---|
| 386 | case COM_GOSUB:
|
---|
| 387 | OpcodeGosub(Command+2);
|
---|
| 388 | break;
|
---|
| 389 | case COM_RETURN:
|
---|
| 390 | OpcodeReturn(Command+2);
|
---|
| 391 | break;
|
---|
| 392 |
|
---|
| 393 | case COM_SETDOUBLE:
|
---|
| 394 | OpcodeSetPtrData(Command+2,DEF_DOUBLE);
|
---|
| 395 | break;
|
---|
| 396 | case COM_SETSINGLE:
|
---|
| 397 | OpcodeSetPtrData(Command+2,DEF_SINGLE);
|
---|
| 398 | break;
|
---|
| 399 | case COM_SETQWORD:
|
---|
| 400 | OpcodeSetPtrData(Command+2,DEF_QWORD);
|
---|
| 401 | break;
|
---|
| 402 | case COM_SETDWORD:
|
---|
| 403 | OpcodeSetPtrData(Command+2,DEF_DWORD);
|
---|
| 404 | break;
|
---|
| 405 | case COM_SETWORD:
|
---|
| 406 | OpcodeSetPtrData(Command+2,DEF_WORD);
|
---|
| 407 | break;
|
---|
| 408 | case COM_SETBYTE:
|
---|
| 409 | OpcodeSetPtrData(Command+2,DEF_BYTE);
|
---|
| 410 | break;
|
---|
| 411 |
|
---|
| 412 | case COM_DEBUG:
|
---|
| 413 | extern BOOL bDebugCompile;
|
---|
| 414 | //int 3
|
---|
[253] | 415 | if(bDebugCompile)
|
---|
| 416 | {
|
---|
| 417 | breakpoint;
|
---|
| 418 | }
|
---|
| 419 | else
|
---|
| 420 | {
|
---|
[263] | 421 | //#if defined(_DEBUG)
|
---|
[253] | 422 | breakpoint;
|
---|
[263] | 423 | //#endif
|
---|
[253] | 424 | }
|
---|
[4] | 425 | break;
|
---|
| 426 |
|
---|
| 427 | case COM_LET:
|
---|
| 428 | OpcodeCalc(Command+2);
|
---|
| 429 | break;
|
---|
| 430 | default:
|
---|
| 431 | OpcodeOthers(Command);
|
---|
| 432 | break;
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | void GetGlobalDataForDll(void){
|
---|
| 437 | extern char *basbuf;
|
---|
| 438 | extern HANDLE hHeap;
|
---|
| 439 | int i2,BufferSize;
|
---|
| 440 | char *Command;
|
---|
| 441 | DWORD dwRetCode;
|
---|
| 442 |
|
---|
| 443 | dwRetCode=0;
|
---|
| 444 | BufferSize=128;
|
---|
| 445 | Command=(char *)HeapAlloc(hHeap,0,BufferSize);
|
---|
| 446 | for(cp++,i2=0;;cp++,i2++){
|
---|
| 447 | if(i2>=BufferSize){
|
---|
| 448 | //バッファ領域が足りなくなった場合はバッファを増量する
|
---|
| 449 | BufferSize+=128;
|
---|
| 450 | Command=(char *)HeapReAlloc(hHeap,0,Command,BufferSize);
|
---|
| 451 | }
|
---|
| 452 | if(basbuf[cp]=='\"'){
|
---|
| 453 | Command[i2]=basbuf[cp];
|
---|
| 454 | for(cp++,i2++;;cp++,i2++){
|
---|
| 455 | if(i2>=BufferSize){
|
---|
| 456 | //バッファ領域が足りなくなった場合はバッファを増量する
|
---|
| 457 | BufferSize+=128;
|
---|
| 458 | Command=(char *)HeapReAlloc(hHeap,0,Command,BufferSize);
|
---|
| 459 | }
|
---|
| 460 | Command[i2]=basbuf[cp];
|
---|
| 461 | if(basbuf[cp]=='\"') break;
|
---|
| 462 | }
|
---|
| 463 | continue;
|
---|
| 464 | }
|
---|
| 465 | if(IsCommandDelimitation(basbuf[cp])){
|
---|
| 466 | Command[i2]=0;
|
---|
| 467 |
|
---|
| 468 | if(Command[0]==1&&Command[1]==ESC_SUB){
|
---|
| 469 | i2=cp;
|
---|
| 470 | while(!(basbuf[cp]==1&&basbuf[cp+1]==ESC_ENDSUB)){
|
---|
| 471 | if(basbuf[cp]=='\0'){
|
---|
| 472 | SetError(22,"Sub",i2);
|
---|
| 473 | break;
|
---|
| 474 | }
|
---|
| 475 | cp++;
|
---|
| 476 | }
|
---|
| 477 | if(basbuf[cp+2]=='\0'||basbuf[cp]=='\0') break;
|
---|
| 478 | cp+=2;
|
---|
| 479 | i2=-1;
|
---|
| 480 | continue;
|
---|
| 481 | }
|
---|
| 482 | if(Command[0]==1&&Command[1]==ESC_FUNCTION){
|
---|
| 483 | i2=cp;
|
---|
| 484 | while(!(basbuf[cp]==1&&basbuf[cp+1]==ESC_ENDFUNCTION)){
|
---|
| 485 | if(basbuf[cp]=='\0'){
|
---|
| 486 | SetError(22,"Function",i2);
|
---|
| 487 | break;
|
---|
| 488 | }
|
---|
| 489 | cp++;
|
---|
| 490 | }
|
---|
| 491 | if(basbuf[cp+2]=='\0'||basbuf[cp]=='\0') break;
|
---|
| 492 | cp+=2;
|
---|
| 493 | i2=-1;
|
---|
| 494 | continue;
|
---|
| 495 | }
|
---|
| 496 | if(Command[0]==1&&Command[1]==ESC_MACRO){
|
---|
| 497 | i2=cp;
|
---|
| 498 | while(!(basbuf[cp]==1&&basbuf[cp+1]==ESC_ENDMACRO)){
|
---|
| 499 | if(basbuf[cp]=='\0'){
|
---|
| 500 | SetError(22,"Macro",i2);
|
---|
| 501 | break;
|
---|
| 502 | }
|
---|
| 503 | cp++;
|
---|
| 504 | }
|
---|
| 505 | if(basbuf[cp+2]=='\0'||basbuf[cp]=='\0') break;
|
---|
| 506 | cp+=2;
|
---|
| 507 | i2=-1;
|
---|
| 508 | continue;
|
---|
| 509 | }
|
---|
| 510 | if(Command[0]==1&&Command[1]==ESC_TYPE){
|
---|
| 511 | i2=cp;
|
---|
| 512 | while(!(basbuf[cp]==1&&basbuf[cp+1]==ESC_ENDTYPE)){
|
---|
| 513 | if(basbuf[cp]=='\0'){
|
---|
| 514 | SetError(22,"Type",i2);
|
---|
| 515 | break;
|
---|
| 516 | }
|
---|
| 517 | cp++;
|
---|
| 518 | }
|
---|
| 519 | if(basbuf[cp+2]=='\0'||basbuf[cp]=='\0') break;
|
---|
| 520 | cp+=2;
|
---|
| 521 | i2=-1;
|
---|
| 522 | continue;
|
---|
| 523 | }
|
---|
| 524 | if(Command[0]==1&&Command[1]==ESC_CLASS){
|
---|
| 525 | i2=cp;
|
---|
| 526 | while(!(basbuf[cp]==1&&basbuf[cp+1]==ESC_ENDCLASS)){
|
---|
| 527 | if(basbuf[cp]=='\0'){
|
---|
| 528 | SetError(22,"Class",i2);
|
---|
| 529 | break;
|
---|
| 530 | }
|
---|
| 531 | cp++;
|
---|
| 532 | }
|
---|
| 533 | if(basbuf[cp+2]=='\0'||basbuf[cp]=='\0') break;
|
---|
| 534 | cp+=2;
|
---|
| 535 | i2=-1;
|
---|
| 536 | continue;
|
---|
| 537 | }
|
---|
| 538 | if(Command[0]==1&&Command[1]==ESC_INTERFACE){
|
---|
| 539 | i2=cp;
|
---|
| 540 | while(!(basbuf[cp]==1&&basbuf[cp+1]==ESC_ENDINTERFACE)){
|
---|
| 541 | if(basbuf[cp]=='\0'){
|
---|
| 542 | SetError(22,"Interface",i2);
|
---|
| 543 | break;
|
---|
| 544 | }
|
---|
| 545 | cp++;
|
---|
| 546 | }
|
---|
| 547 | if(basbuf[cp+2]=='\0'||basbuf[cp]=='\0') break;
|
---|
| 548 | cp+=2;
|
---|
| 549 | i2=-1;
|
---|
| 550 | continue;
|
---|
| 551 | }
|
---|
| 552 |
|
---|
| 553 | //DLLのグローバルデータに必要なコマンドだけ
|
---|
| 554 | if(MAKEWORD(Command[1],Command[0])==COM_DIM)
|
---|
| 555 | OpcodeDim(Command+2,0);
|
---|
| 556 |
|
---|
| 557 | if(basbuf[cp]=='\0') break;
|
---|
| 558 | i2=-1;
|
---|
| 559 | continue;
|
---|
| 560 | }
|
---|
| 561 | Command[i2]=basbuf[cp];
|
---|
| 562 | }
|
---|
| 563 | HeapDefaultFree(Command);
|
---|
| 564 | }
|
---|
| 565 | DWORD CompileBuffer(char Return_Sequence,WORD Return_Command){
|
---|
| 566 | extern char *basbuf;
|
---|
| 567 | extern HANDLE hHeap;
|
---|
| 568 | int i,i2,i3,i4,BufferSize,ScopeStart;
|
---|
| 569 | char *Command,temporary[VN_SIZE],*temp2,temp3[32];
|
---|
| 570 | DWORD dwRetCode;
|
---|
| 571 |
|
---|
| 572 | ScopeStart=cp;
|
---|
| 573 |
|
---|
| 574 | dwRetCode=0;
|
---|
| 575 | BufferSize=128;
|
---|
| 576 | Command=(char *)HeapAlloc(hHeap,0,BufferSize);
|
---|
[15] | 577 |
|
---|
[4] | 578 | for(cp++,i2=0;;cp++,i2++){
|
---|
| 579 | if(i2>=BufferSize){
|
---|
| 580 | //バッファ領域が足りなくなった場合はバッファを増量する
|
---|
| 581 | BufferSize+=128;
|
---|
| 582 | Command=(char *)HeapReAlloc(hHeap,0,Command,BufferSize);
|
---|
| 583 | }
|
---|
| 584 | if(basbuf[cp]=='\"'){
|
---|
| 585 | Command[i2]=basbuf[cp];
|
---|
| 586 | for(cp++,i2++;;cp++,i2++){
|
---|
| 587 | if(i2>=BufferSize){
|
---|
| 588 | //バッファ領域が足りなくなった場合はバッファを増量する
|
---|
| 589 | BufferSize+=128;
|
---|
| 590 | Command=(char *)HeapReAlloc(hHeap,0,Command,BufferSize);
|
---|
| 591 | }
|
---|
| 592 | Command[i2]=basbuf[cp];
|
---|
| 593 | if(basbuf[cp]=='\"') break;
|
---|
| 594 | }
|
---|
| 595 | continue;
|
---|
| 596 | }
|
---|
| 597 | if(IsCommandDelimitation(basbuf[cp])){
|
---|
| 598 | Command[i2]=0;
|
---|
| 599 |
|
---|
| 600 | if(Command[0]==1&&Command[1]==ESC_LINENUM){
|
---|
| 601 | for(i=2,i2=0;;i++,i2++){
|
---|
| 602 | if(Command[i]==','){
|
---|
| 603 | temporary[i2]=0;
|
---|
| 604 | break;
|
---|
| 605 | }
|
---|
| 606 | temporary[i2]=Command[i];
|
---|
| 607 | }
|
---|
| 608 | i3=atoi(temporary);
|
---|
| 609 | i4=i+1;
|
---|
| 610 |
|
---|
| 611 | //Goto先ラベル
|
---|
[276] | 612 | compiler.codeGenerator.gotoLabels.push_back( GotoLabel( (long)i3, compiler.codeGenerator.GetNativeCodeSize() ) );
|
---|
[4] | 613 |
|
---|
| 614 | //書き込みスケジュール
|
---|
[253] | 615 | GotoLabelSchedules::iterator it = compiler.codeGenerator.gotoLabelSchedules.begin();
|
---|
[246] | 616 | while( it != compiler.codeGenerator.gotoLabelSchedules.end() )
|
---|
| 617 | {
|
---|
[253] | 618 | if( (*it)->GetName().size() == 0 && (*it)->GetLineNum() == i3 )
|
---|
[246] | 619 | {
|
---|
[253] | 620 | compiler.codeGenerator.opfix_JmpPertialSchedule( (*it) );
|
---|
| 621 |
|
---|
[4] | 622 | //詰める
|
---|
[246] | 623 | it = compiler.codeGenerator.gotoLabelSchedules.erase( it );
|
---|
[4] | 624 | }
|
---|
[246] | 625 | else
|
---|
| 626 | {
|
---|
| 627 | it++;
|
---|
| 628 | }
|
---|
[4] | 629 | }
|
---|
| 630 |
|
---|
| 631 | temp2=(char *)HeapAlloc(hHeap,0,lstrlen(Command+i4)+1);
|
---|
| 632 | lstrcpy(temp2,Command+i4);
|
---|
| 633 | lstrcpy(Command,temp2);
|
---|
| 634 | HeapDefaultFree(temp2);
|
---|
| 635 | }
|
---|
| 636 |
|
---|
| 637 | if(Command[0]==1&&
|
---|
| 638 | (((Command[1]==ESC_VIRTUAL||Command[1]==ESC_OVERRIDE)&&Command[2]==1&&(Command[3]==ESC_SUB||Command[3]==ESC_FUNCTION))||
|
---|
| 639 | Command[1]==ESC_SUB||
|
---|
| 640 | Command[1]==ESC_FUNCTION||
|
---|
| 641 | Command[1]==ESC_MACRO||
|
---|
| 642 | Command[1]==ESC_TYPE||
|
---|
| 643 | Command[1]==ESC_CLASS||
|
---|
| 644 | Command[1]==ESC_INTERFACE||
|
---|
| 645 | Command[1]==ESC_ENUM||
|
---|
| 646 | (Command[1]==ESC_CONST&&Command[2]==1&&Command[3]==ESC_ENUM)
|
---|
| 647 | )
|
---|
| 648 | ){
|
---|
| 649 | if(Command[1]==ESC_VIRTUAL||Command[1]==ESC_OVERRIDE||Command[1]==ESC_CONST){
|
---|
| 650 | GetDefaultNameFromES(Command[3],temporary);
|
---|
| 651 | }
|
---|
| 652 | else{
|
---|
| 653 | GetDefaultNameFromES(Command[1],temporary);
|
---|
| 654 | }
|
---|
| 655 | if(Return_Sequence){
|
---|
| 656 | SetError(12,temporary,cp);
|
---|
| 657 | break;
|
---|
| 658 | }
|
---|
| 659 |
|
---|
| 660 | if(Command[1]==ESC_CONST) i3=GetEndXXXCommand(Command[3]);
|
---|
| 661 | else i3=GetEndXXXCommand(Command[1]);
|
---|
| 662 | for(i2=cp;;cp++){
|
---|
| 663 | if(basbuf[cp]==1){
|
---|
| 664 | if(basbuf[cp+1]==i3) break;
|
---|
| 665 | if(Command[1]==ESC_CLASS||Command[1]==ESC_INTERFACE){
|
---|
| 666 | //クラス、インターフェイスではSub、Functionの定義を可能にしておく
|
---|
| 667 | if(basbuf[cp+1]==ESC_MACRO||
|
---|
| 668 | basbuf[cp+1]==ESC_TYPE||
|
---|
| 669 | basbuf[cp+1]==ESC_CLASS||
|
---|
| 670 | basbuf[cp+1]==ESC_INTERFACE||
|
---|
| 671 | basbuf[cp+1]==ESC_ENUM){
|
---|
| 672 | GetDefaultNameFromES(basbuf[cp+1],temp3);
|
---|
| 673 | SetError(12,temp3,cp);
|
---|
| 674 | }
|
---|
| 675 | }
|
---|
| 676 | else{
|
---|
| 677 | if(basbuf[cp-1]!='*'&&(
|
---|
| 678 | basbuf[cp+1]==ESC_VIRTUAL||
|
---|
| 679 | basbuf[cp+1]==ESC_OVERRIDE||
|
---|
| 680 | basbuf[cp+1]==ESC_SUB||
|
---|
| 681 | basbuf[cp+1]==ESC_FUNCTION||
|
---|
| 682 | basbuf[cp+1]==ESC_MACRO||
|
---|
| 683 | basbuf[cp+1]==ESC_TYPE||
|
---|
| 684 | basbuf[cp+1]==ESC_CLASS||
|
---|
| 685 | basbuf[cp+1]==ESC_INTERFACE||
|
---|
| 686 | basbuf[cp+1]==ESC_ENUM)){
|
---|
| 687 | GetDefaultNameFromES(basbuf[cp+1],temp3);
|
---|
| 688 | SetError(12,temp3,cp);
|
---|
| 689 | }
|
---|
| 690 | }
|
---|
| 691 | }
|
---|
| 692 | if(basbuf[cp]=='\0'){
|
---|
| 693 | //error
|
---|
| 694 | //既にエラー発行済みのため、何もせずに抜ける
|
---|
| 695 | break;
|
---|
| 696 | }
|
---|
| 697 | }
|
---|
| 698 | if(basbuf[cp+2]=='\0'||basbuf[cp]=='\0') break;
|
---|
| 699 | cp+=2;
|
---|
| 700 | i2=-1;
|
---|
| 701 | continue;
|
---|
| 702 | }
|
---|
| 703 |
|
---|
| 704 | if(Command[0]==0x10||Command[0]==0x11){
|
---|
| 705 | //Wend、Next、Loopなど
|
---|
| 706 | if(Return_Command==MAKEWORD(Command[1],Command[0])){
|
---|
| 707 | if(Return_Command==COM_NEXT){
|
---|
| 708 | //Nextの場合は、パラメータ(省略化)の整合性を判断する必要がある(OpcodeFor関数を参照)
|
---|
| 709 | extern char szNextVariable[VN_SIZE];
|
---|
| 710 | if(Command[2]) lstrcpy(szNextVariable,Command+2);
|
---|
| 711 | else szNextVariable[0]=0;
|
---|
| 712 | }
|
---|
| 713 | break;
|
---|
| 714 | }
|
---|
| 715 | }
|
---|
| 716 |
|
---|
[263] | 717 | compiler.codeGenerator.NextSourceLine();
|
---|
[4] | 718 |
|
---|
| 719 | if(Command[0]==1){
|
---|
| 720 | if(Return_Sequence==ESC_ENDIF&&Command[1]==ESC_ELSE){
|
---|
| 721 | dwRetCode=ESC_ELSE;
|
---|
| 722 | break;
|
---|
| 723 | }
|
---|
| 724 |
|
---|
| 725 | if(Command[1]==Return_Sequence){
|
---|
| 726 | dwRetCode=Command[1];
|
---|
| 727 | break;
|
---|
| 728 | }
|
---|
| 729 | }
|
---|
| 730 |
|
---|
[182] | 731 | try
|
---|
| 732 | {
|
---|
| 733 | ChangeOpcode(Command);
|
---|
| 734 | }
|
---|
| 735 | catch( const SmoothieException &smoothieException )
|
---|
| 736 | {
|
---|
| 737 | SetError(
|
---|
| 738 | smoothieException.GetErrorCode(),
|
---|
| 739 | smoothieException.GetKeyword(),
|
---|
| 740 | smoothieException.GetNowLine()
|
---|
| 741 | );
|
---|
| 742 | }
|
---|
[4] | 743 |
|
---|
[232] | 744 |
|
---|
[4] | 745 | epi_check();
|
---|
| 746 |
|
---|
[232] | 747 |
|
---|
[4] | 748 | //コンパイルを中断するとき
|
---|
| 749 | extern BOOL bStopCompile;
|
---|
| 750 | if(bStopCompile) return 0;
|
---|
| 751 |
|
---|
| 752 | if(basbuf[cp]=='\0'){
|
---|
| 753 | switch(Return_Command){
|
---|
| 754 | case COM_WEND:
|
---|
| 755 | SetError(4,"\"While\" - \"Wend\" ",ScopeStart);
|
---|
| 756 | break;
|
---|
| 757 | case COM_NEXT:
|
---|
| 758 | SetError(4,"\"For\" - \"Next\" ",ScopeStart);
|
---|
| 759 | break;
|
---|
| 760 | case COM_LOOP:
|
---|
| 761 | SetError(4,"\"Do\" - \"Loop\" ",ScopeStart);
|
---|
| 762 | break;
|
---|
| 763 | }
|
---|
| 764 | switch(Return_Sequence){
|
---|
| 765 | case ESC_ENDSUB:
|
---|
| 766 | SetError(4,"\"Sub\" - \"End Sub\" ",ScopeStart);
|
---|
| 767 | break;
|
---|
| 768 | case ESC_ENDFUNCTION:
|
---|
| 769 | SetError(4,"\"Function\" - \"End Function\" ",ScopeStart);
|
---|
| 770 | break;
|
---|
| 771 | case ESC_ENDMACRO:
|
---|
| 772 | SetError(4,"\"Macro\" - \"End Macro\" ",ScopeStart);
|
---|
| 773 | break;
|
---|
| 774 | case ESC_ENDIF:
|
---|
| 775 | SetError(22,"If",ScopeStart);
|
---|
| 776 | break;
|
---|
| 777 | }
|
---|
| 778 | break;
|
---|
| 779 | }
|
---|
| 780 | i2=-1;
|
---|
| 781 | continue;
|
---|
| 782 | }
|
---|
| 783 | Command[i2]=basbuf[cp];
|
---|
| 784 | }
|
---|
| 785 | HeapDefaultFree(Command);
|
---|
| 786 |
|
---|
| 787 | return dwRetCode;
|
---|
| 788 | }
|
---|