Changeset 230 for branches/xpascal/Executor.pas
- Timestamp:
- Jun 26, 2023, 12:08:45 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/xpascal/Executor.pas
r229 r230 4 4 5 5 uses 6 Classes, SysUtils, Source, Contnrs;6 Classes, SysUtils, Source, Generics.Collections; 7 7 8 8 type … … 21 21 { TExecutorVariables } 22 22 23 TExecutorVariables = class(TObjectList )23 TExecutorVariables = class(TObjectList<TExecutorVariable>) 24 24 function SearchByVariable(Variable: TVariable): TExecutorVariable; 25 25 function AddNew(Variable: TVariable): TExecutorVariable; … … 37 37 { TExecutorTypes } 38 38 39 TExecutorTypes = class(TObjectList )39 TExecutorTypes = class(TObjectList<TExecutorType>) 40 40 function SearchByType(TypeRef: TType): TExecutorType; 41 41 function AddNew(TypeRef: TType): TExecutorType; 42 42 end; 43 43 44 TExecutorFunctionCallback = function(Params: array of TValue): TValue of object; 44 { TExecutorFunctionCallbackParam } 45 46 TExecutorFunctionCallbackParam = class 47 Kind: TFunctionParamKind; 48 Variable: TExecutorVariable; 49 Value: TValue; 50 destructor Destroy; override; 51 end; 52 53 TExecutorFunctionCallback = function(Params: array of TExecutorFunctionCallbackParam): 54 TValue of object; 45 55 46 56 { TExecutorFunction } … … 56 66 { TExecutorFunctions } 57 67 58 TExecutorFunctions = class(TObjectList )68 TExecutorFunctions = class(TObjectList<TExecutorFunction>) 59 69 function SearchByFunction(FunctionDef: TFunction): TExecutorFunction; 60 70 function AddNew(FunctionDef: TFunction): TExecutorFunction; … … 78 88 79 89 TOutputEvent = procedure (Text: string) of object; 90 TInputEvent = function: string of object; 80 91 81 92 { TExecutor } … … 84 95 private 85 96 FOnOutput: TOutputEvent; 97 FOnInput: TInputEvent; 86 98 SystemBlock: TExecutorBlock; 87 function ExecuteWriteLn(Params: array of TValue): TValue; 88 function ExecuteWrite(Params: array of TValue): TValue; 89 function ExecuteIntToStr(Params: array of TValue): TValue; 90 function ExecuteStrToInt(Params: array of TValue): TValue; 91 function ExecuteBooleanAssign(Params: array of TValue): TValue; 92 function ExecuteBooleanNot(Params: array of TValue): TValue; 93 function ExecuteBooleanEqual(Params: array of TValue): TValue; 94 function ExecuteBooleanNotEqual(Params: array of TValue): TValue; 95 function ExecuteStringAssign(Params: array of TValue): TValue; 96 function ExecuteStringAdd(Params: array of TValue): TValue; 97 function ExecuteStringEqual(Params: array of TValue): TValue; 98 function ExecuteStringNotEqual(Params: array of TValue): TValue; 99 function ExecuteIntegerAssign(Params: array of TValue): TValue; 100 function ExecuteIntegerAdd(Params: array of TValue): TValue; 101 function ExecuteIntegerSub(Params: array of TValue): TValue; 102 function ExecuteIntegerMul(Params: array of TValue): TValue; 103 function ExecuteIntegerIntDiv(Params: array of TValue): TValue; 104 function ExecuteIntegerMod(Params: array of TValue): TValue; 105 function ExecuteIntegerEqual(Params: array of TValue): TValue; 106 function ExecuteIntegerNotEqual(Params: array of TValue): TValue; 107 function ExecuteIntegerLesser(Params: array of TValue): TValue; 108 function ExecuteIntegerHigher(Params: array of TValue): TValue; 109 function ExecuteIntegerLesserOrEqual(Params: array of TValue): TValue; 110 function ExecuteIntegerHigherOrEqual(Params: array of TValue): TValue; 111 function ExecuteIntegerAnd(Params: array of TValue): TValue; 112 function ExecuteIntegerOr(Params: array of TValue): TValue; 113 function ExecuteIntegerXor(Params: array of TValue): TValue; 114 function ExecuteIntegerShr(Params: array of TValue): TValue; 115 function ExecuteIntegerShl(Params: array of TValue): TValue; 99 function ExecuteWriteLn(Params: array of TExecutorFunctionCallbackParam): TValue; 100 function ExecuteWrite(Params: array of TExecutorFunctionCallbackParam): TValue; 101 function ExecuteReadLn(Params: array of TExecutorFunctionCallbackParam): TValue; 102 function ExecuteRead(Params: array of TExecutorFunctionCallbackParam): TValue; 103 function ExecuteIntToStr(Params: array of TExecutorFunctionCallbackParam): TValue; 104 function ExecuteStrToInt(Params: array of TExecutorFunctionCallbackParam): TValue; 105 function ExecuteBoolToStr(Params: array of TExecutorFunctionCallbackParam): TValue; 106 function ExecuteStrToBool(Params: array of TExecutorFunctionCallbackParam): TValue; 107 function ExecuteBooleanAssign(Params: array of TExecutorFunctionCallbackParam): TValue; 108 function ExecuteBooleanNot(Params: array of TExecutorFunctionCallbackParam): TValue; 109 function ExecuteBooleanEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 110 function ExecuteBooleanNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 111 function ExecuteStringAssign(Params: array of TExecutorFunctionCallbackParam): TValue; 112 function ExecuteStringAdd(Params: array of TExecutorFunctionCallbackParam): TValue; 113 function ExecuteStringEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 114 function ExecuteStringNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 115 function ExecuteIntegerAssign(Params: array of TExecutorFunctionCallbackParam): TValue; 116 function ExecuteIntegerAdd(Params: array of TExecutorFunctionCallbackParam): TValue; 117 function ExecuteIntegerSub(Params: array of TExecutorFunctionCallbackParam): TValue; 118 function ExecuteIntegerMul(Params: array of TExecutorFunctionCallbackParam): TValue; 119 function ExecuteIntegerIntDiv(Params: array of TExecutorFunctionCallbackParam): TValue; 120 function ExecuteIntegerMod(Params: array of TExecutorFunctionCallbackParam): TValue; 121 function ExecuteIntegerEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 122 function ExecuteIntegerNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 123 function ExecuteIntegerLesser(Params: array of TExecutorFunctionCallbackParam): TValue; 124 function ExecuteIntegerHigher(Params: array of TExecutorFunctionCallbackParam): TValue; 125 function ExecuteIntegerLesserOrEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 126 function ExecuteIntegerHigherOrEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 127 function ExecuteIntegerAnd(Params: array of TExecutorFunctionCallbackParam): TValue; 128 function ExecuteIntegerOr(Params: array of TExecutorFunctionCallbackParam): TValue; 129 function ExecuteIntegerXor(Params: array of TExecutorFunctionCallbackParam): TValue; 130 function ExecuteIntegerShr(Params: array of TExecutorFunctionCallbackParam): TValue; 131 function ExecuteIntegerShl(Params: array of TExecutorFunctionCallbackParam): TValue; 116 132 procedure InitExecutorBlock(ExecutorBlock: TExecutorBlock; Block: TBlock); 117 133 public … … 135 151 procedure Run; 136 152 procedure Output(Text: string); 153 function Input: string; 137 154 property OnOutput: TOutputEvent read FOnOutput write FOnOutput; 155 property OnInput: TInputEvent read FOnInput write FOnInput; 138 156 end; 139 157 140 158 141 159 implementation 160 161 resourcestring 162 SUnsupportedOperandType = 'Unsupported exception operand type.'; 163 SUnsupportedCommandType = 'Unsupported command type.'; 164 SExpectedBooleanValue = 'Expected boolean value.'; 165 166 { TExecutorFunctionCallbackParam } 167 168 destructor TExecutorFunctionCallbackParam.Destroy; 169 begin 170 FreeAndNil(Value); 171 inherited; 172 end; 142 173 143 174 { TExecutorFunction } … … 293 324 { TExecutor } 294 325 295 function TExecutor.ExecuteWriteLn(Params: array of T Value): TValue;326 function TExecutor.ExecuteWriteLn(Params: array of TExecutorFunctionCallbackParam): TValue; 296 327 var 297 328 I: Integer; … … 301 332 Text := ''; 302 333 for I := 0 to Length(Params) - 1 do 303 Text := Text + TValueString(Params[I] ).Value;334 Text := Text + TValueString(Params[I].Value).Value; 304 335 Output(Text + LineEnding); 305 336 end; 306 337 307 function TExecutor.ExecuteWrite(Params: array of T Value): TValue;338 function TExecutor.ExecuteWrite(Params: array of TExecutorFunctionCallbackParam): TValue; 308 339 var 309 340 I: Integer; … … 313 344 Text := ''; 314 345 for I := 0 to Length(Params) - 1 do 315 Text := Text + TValueString(Params[I] ).Value;346 Text := Text + TValueString(Params[I].Value).Value; 316 347 Output(Text); 317 348 end; 318 349 319 function TExecutor.ExecuteIntToStr(Params: array of TValue): TValue; 350 function TExecutor.ExecuteReadLn(Params: array of TExecutorFunctionCallbackParam): TValue; 351 var 352 I: Integer; 353 begin 354 Result := nil; 355 for I := 0 to Length(Params) - 1 do 356 TValueString(Params[I].Variable.Value).Value := Input; 357 Output(LineEnding); 358 end; 359 360 function TExecutor.ExecuteRead(Params: array of TExecutorFunctionCallbackParam): TValue; 361 var 362 I: Integer; 363 begin 364 Result := nil; 365 for I := 0 to Length(Params) - 1 do 366 TValueString(Params[I].Value).Value := Input; 367 end; 368 369 function TExecutor.ExecuteIntToStr(Params: array of TExecutorFunctionCallbackParam): TValue; 320 370 begin 321 371 Result := TValueString.Create; 322 TValueString(Result).Value := IntToStr(TValueInteger(Params[0]).Value); 323 end; 324 325 function TExecutor.ExecuteStrToInt(Params: array of TValue): TValue; 326 begin 327 Result := TValueInteger.Create; 328 TValueInteger(Result).Value := StrToInt(TValueString(Params[0]).Value); 329 end; 330 331 function TExecutor.ExecuteBooleanAssign(Params: array of TValue): TValue; 332 begin 333 Result := TValueBoolean.Create; 334 TValueBoolean(Result).Value := TValueBoolean(Params[0]).Value; 335 end; 336 337 function TExecutor.ExecuteBooleanNot(Params: array of TValue): TValue; 338 begin 339 Result := TValueBoolean.Create; 340 TValueBoolean(Result).Value := not TValueBoolean(Params[0]).Value; 341 end; 342 343 function TExecutor.ExecuteBooleanEqual(Params: array of TValue): TValue; 344 begin 345 Result := TValueBoolean.Create; 346 TValueBoolean(Result).Value := TValueBoolean(Params[0]).Value = TValueBoolean(Params[1]).Value; 347 end; 348 349 function TExecutor.ExecuteBooleanNotEqual(Params: array of TValue): TValue; 350 begin 351 Result := TValueBoolean.Create; 352 TValueBoolean(Result).Value := TValueBoolean(Params[0]).Value <> TValueBoolean(Params[1]).Value; 353 end; 354 355 function TExecutor.ExecuteStringAssign(Params: array of TValue): TValue; 372 TValueString(Result).Value := IntToStr(TValueInteger(Params[0].Value).Value); 373 end; 374 375 function TExecutor.ExecuteStrToInt(Params: array of TExecutorFunctionCallbackParam): TValue; 376 begin 377 Result := TValueInteger.Create; 378 TValueInteger(Result).Value := StrToInt(TValueString(Params[0].Value).Value); 379 end; 380 381 function TExecutor.ExecuteBoolToStr(Params: array of TExecutorFunctionCallbackParam): TValue; 356 382 begin 357 383 Result := TValueString.Create; 358 TValueString(Result).Value := TValueString(Params[0]).Value; 359 end; 360 361 function TExecutor.ExecuteStringAdd(Params: array of TValue): TValue; 384 TValueString(Result).Value := BoolToStr(TValueBoolean(Params[0].Value).Value); 385 end; 386 387 function TExecutor.ExecuteStrToBool(Params: array of TExecutorFunctionCallbackParam): TValue; 388 begin 389 Result := TValueBoolean.Create; 390 TValueBoolean(Result).Value := StrToBool(TValueString(Params[0].Value).Value); 391 end; 392 393 function TExecutor.ExecuteBooleanAssign(Params: array of TExecutorFunctionCallbackParam): TValue; 394 begin 395 Result := TValueBoolean.Create; 396 TValueBoolean(Result).Value := TValueBoolean(Params[0].Value).Value; 397 end; 398 399 function TExecutor.ExecuteBooleanNot(Params: array of TExecutorFunctionCallbackParam): TValue; 400 begin 401 Result := TValueBoolean.Create; 402 TValueBoolean(Result).Value := not TValueBoolean(Params[0].Value).Value; 403 end; 404 405 function TExecutor.ExecuteBooleanEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 406 begin 407 Result := TValueBoolean.Create; 408 TValueBoolean(Result).Value := TValueBoolean(Params[0].Value).Value = 409 TValueBoolean(Params[1].Value).Value; 410 end; 411 412 function TExecutor.ExecuteBooleanNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 413 begin 414 Result := TValueBoolean.Create; 415 TValueBoolean(Result).Value := TValueBoolean(Params[0].Value).Value <> 416 TValueBoolean(Params[1].Value).Value; 417 end; 418 419 function TExecutor.ExecuteStringAssign(Params: array of TExecutorFunctionCallbackParam): TValue; 362 420 begin 363 421 Result := TValueString.Create; 364 TValueString(Result).Value := TValueString(Params[0]).Value + TValueString(Params[1]).Value; 365 end; 366 367 function TExecutor.ExecuteStringEqual(Params: array of TValue): TValue; 368 begin 369 Result := TValueBoolean.Create; 370 TValueBoolean(Result).Value := TValueString(Params[0]).Value = TValueString(Params[1]).Value; 371 end; 372 373 function TExecutor.ExecuteStringNotEqual(Params: array of TValue): TValue; 374 begin 375 Result := TValueBoolean.Create; 376 TValueBoolean(Result).Value := TValueString(Params[0]).Value <> TValueString(Params[1]).Value; 377 end; 378 379 function TExecutor.ExecuteIntegerAssign(Params: array of TValue): TValue; 380 begin 381 Result := TValueInteger.Create; 382 TValueInteger(Result).Value := TValueInteger(Params[0]).Value; 383 end; 384 385 function TExecutor.ExecuteIntegerAdd(Params: array of TValue): TValue; 386 begin 387 Result := TValueInteger.Create; 388 TValueInteger(Result).Value := TValueInteger(Params[0]).Value + TValueInteger(Params[1]).Value; 389 end; 390 391 function TExecutor.ExecuteIntegerSub(Params: array of TValue): TValue; 392 begin 393 Result := TValueInteger.Create; 394 TValueInteger(Result).Value := TValueInteger(Params[0]).Value - TValueInteger(Params[1]).Value; 395 end; 396 397 function TExecutor.ExecuteIntegerMul(Params: array of TValue): TValue; 398 begin 399 Result := TValueInteger.Create; 400 TValueInteger(Result).Value := TValueInteger(Params[0]).Value * TValueInteger(Params[1]).Value; 401 end; 402 403 function TExecutor.ExecuteIntegerIntDiv(Params: array of TValue): TValue; 404 begin 405 Result := TValueInteger.Create; 406 TValueInteger(Result).Value := TValueInteger(Params[0]).Value div TValueInteger(Params[1]).Value; 407 end; 408 409 function TExecutor.ExecuteIntegerMod(Params: array of TValue): TValue; 410 begin 411 Result := TValueInteger.Create; 412 TValueInteger(Result).Value := TValueInteger(Params[0]).Value mod TValueInteger(Params[1]).Value; 413 end; 414 415 function TExecutor.ExecuteIntegerEqual(Params: array of TValue): TValue; 416 begin 417 Result := TValueBoolean.Create; 418 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value = TValueInteger(Params[1]).Value; 419 end; 420 421 function TExecutor.ExecuteIntegerNotEqual(Params: array of TValue): TValue; 422 begin 423 Result := TValueBoolean.Create; 424 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value <> TValueInteger(Params[1]).Value; 425 end; 426 427 function TExecutor.ExecuteIntegerLesser(Params: array of TValue): TValue; 428 begin 429 Result := TValueBoolean.Create; 430 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value < TValueInteger(Params[1]).Value; 431 end; 432 433 function TExecutor.ExecuteIntegerHigher(Params: array of TValue): TValue; 434 begin 435 Result := TValueBoolean.Create; 436 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value > TValueInteger(Params[1]).Value; 437 end; 438 439 function TExecutor.ExecuteIntegerLesserOrEqual(Params: array of TValue): TValue; 440 begin 441 Result := TValueBoolean.Create; 442 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value <= TValueInteger(Params[1]).Value; 443 end; 444 445 function TExecutor.ExecuteIntegerHigherOrEqual(Params: array of TValue): TValue; 446 begin 447 Result := TValueBoolean.Create; 448 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value >= TValueInteger(Params[1]).Value; 449 end; 450 451 function TExecutor.ExecuteIntegerAnd(Params: array of TValue): TValue; 452 begin 453 Result := TValueInteger.Create; 454 TValueInteger(Result).Value := TValueInteger(Params[0]).Value and TValueInteger(Params[1]).Value; 455 end; 456 457 function TExecutor.ExecuteIntegerOr(Params: array of TValue): TValue; 458 begin 459 Result := TValueInteger.Create; 460 TValueInteger(Result).Value := TValueInteger(Params[0]).Value or TValueInteger(Params[1]).Value; 461 end; 462 463 function TExecutor.ExecuteIntegerXor(Params: array of TValue): TValue; 464 begin 465 Result := TValueInteger.Create; 466 TValueInteger(Result).Value := TValueInteger(Params[0]).Value xor TValueInteger(Params[1]).Value; 467 end; 468 469 function TExecutor.ExecuteIntegerShr(Params: array of TValue): TValue; 470 begin 471 Result := TValueInteger.Create; 472 TValueInteger(Result).Value := TValueInteger(Params[0]).Value shr TValueInteger(Params[1]).Value; 473 end; 474 475 function TExecutor.ExecuteIntegerShl(Params: array of TValue): TValue; 476 begin 477 Result := TValueInteger.Create; 478 TValueInteger(Result).Value := TValueInteger(Params[0]).Value shl TValueInteger(Params[1]).Value; 422 TValueString(Result).Value := TValueString(Params[0].Value).Value; 423 end; 424 425 function TExecutor.ExecuteStringAdd(Params: array of TExecutorFunctionCallbackParam): TValue; 426 begin 427 Result := TValueString.Create; 428 TValueString(Result).Value := TValueString(Params[0].Value).Value + 429 TValueString(Params[1].Value).Value; 430 end; 431 432 function TExecutor.ExecuteStringEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 433 begin 434 Result := TValueBoolean.Create; 435 TValueBoolean(Result).Value := TValueString(Params[0].Value).Value = 436 TValueString(Params[1].Value).Value; 437 end; 438 439 function TExecutor.ExecuteStringNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 440 begin 441 Result := TValueBoolean.Create; 442 TValueBoolean(Result).Value := TValueString(Params[0].Value).Value <> 443 TValueString(Params[1].Value).Value; 444 end; 445 446 function TExecutor.ExecuteIntegerAssign(Params: array of TExecutorFunctionCallbackParam): TValue; 447 begin 448 Result := TValueInteger.Create; 449 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value; 450 end; 451 452 function TExecutor.ExecuteIntegerAdd(Params: array of TExecutorFunctionCallbackParam): TValue; 453 begin 454 Result := TValueInteger.Create; 455 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value + 456 TValueInteger(Params[1].Value).Value; 457 end; 458 459 function TExecutor.ExecuteIntegerSub(Params: array of TExecutorFunctionCallbackParam): TValue; 460 begin 461 Result := TValueInteger.Create; 462 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value - 463 TValueInteger(Params[1].Value).Value; 464 end; 465 466 function TExecutor.ExecuteIntegerMul(Params: array of TExecutorFunctionCallbackParam): TValue; 467 begin 468 Result := TValueInteger.Create; 469 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value * 470 TValueInteger(Params[1].Value).Value; 471 end; 472 473 function TExecutor.ExecuteIntegerIntDiv(Params: array of TExecutorFunctionCallbackParam): TValue; 474 begin 475 Result := TValueInteger.Create; 476 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value div 477 TValueInteger(Params[1].Value).Value; 478 end; 479 480 function TExecutor.ExecuteIntegerMod(Params: array of TExecutorFunctionCallbackParam): TValue; 481 begin 482 Result := TValueInteger.Create; 483 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value mod 484 TValueInteger(Params[1].Value).Value; 485 end; 486 487 function TExecutor.ExecuteIntegerEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 488 begin 489 Result := TValueBoolean.Create; 490 TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value = 491 TValueInteger(Params[1].Value).Value; 492 end; 493 494 function TExecutor.ExecuteIntegerNotEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 495 begin 496 Result := TValueBoolean.Create; 497 TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value <> 498 TValueInteger(Params[1].Value).Value; 499 end; 500 501 function TExecutor.ExecuteIntegerLesser(Params: array of TExecutorFunctionCallbackParam): TValue; 502 begin 503 Result := TValueBoolean.Create; 504 TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value < 505 TValueInteger(Params[1].Value).Value; 506 end; 507 508 function TExecutor.ExecuteIntegerHigher(Params: array of TExecutorFunctionCallbackParam): TValue; 509 begin 510 Result := TValueBoolean.Create; 511 TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value > 512 TValueInteger(Params[1].Value).Value; 513 end; 514 515 function TExecutor.ExecuteIntegerLesserOrEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 516 begin 517 Result := TValueBoolean.Create; 518 TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value <= 519 TValueInteger(Params[1].Value).Value; 520 end; 521 522 function TExecutor.ExecuteIntegerHigherOrEqual(Params: array of TExecutorFunctionCallbackParam): TValue; 523 begin 524 Result := TValueBoolean.Create; 525 TValueBoolean(Result).Value := TValueInteger(Params[0].Value).Value >= 526 TValueInteger(Params[1].Value).Value; 527 end; 528 529 function TExecutor.ExecuteIntegerAnd(Params: array of TExecutorFunctionCallbackParam): TValue; 530 begin 531 Result := TValueInteger.Create; 532 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value and 533 TValueInteger(Params[1].Value).Value; 534 end; 535 536 function TExecutor.ExecuteIntegerOr(Params: array of TExecutorFunctionCallbackParam): TValue; 537 begin 538 Result := TValueInteger.Create; 539 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value or 540 TValueInteger(Params[1].Value).Value; 541 end; 542 543 function TExecutor.ExecuteIntegerXor(Params: array of TExecutorFunctionCallbackParam): TValue; 544 begin 545 Result := TValueInteger.Create; 546 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value xor 547 TValueInteger(Params[1].Value).Value; 548 end; 549 550 function TExecutor.ExecuteIntegerShr(Params: array of TExecutorFunctionCallbackParam): TValue; 551 begin 552 Result := TValueInteger.Create; 553 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value shr 554 TValueInteger(Params[1].Value).Value; 555 end; 556 557 function TExecutor.ExecuteIntegerShl(Params: array of TExecutorFunctionCallbackParam): TValue; 558 begin 559 Result := TValueInteger.Create; 560 TValueInteger(Result).Value := TValueInteger(Params[0].Value).Value shl 561 TValueInteger(Params[1].Value).Value; 479 562 end; 480 563 … … 582 665 if ExecutorFunction.FunctionDef.Name = 'WriteLn' then begin 583 666 ExecutorFunction.Callback := ExecuteWriteLn; 584 end; 667 end else 668 if ExecutorFunction.FunctionDef.Name = 'Read' then begin 669 ExecutorFunction.Callback := ExecuteRead; 670 end else 671 if ExecutorFunction.FunctionDef.Name = 'ReadLn' then begin 672 ExecutorFunction.Callback := ExecuteReadLn; 673 end else 585 674 if ExecutorFunction.FunctionDef.Name = 'IntToStr' then begin 586 675 ExecutorFunction.Callback := ExecuteIntToStr; … … 588 677 if ExecutorFunction.FunctionDef.Name = 'StrToInt' then begin 589 678 ExecutorFunction.Callback := ExecuteStrToInt; 679 end else 680 if ExecutorFunction.FunctionDef.Name = 'BoolToStr' then begin 681 ExecutorFunction.Callback := ExecuteBoolToStr; 682 end else 683 if ExecutorFunction.FunctionDef.Name = 'StrToBool' then begin 684 ExecutorFunction.Callback := ExecuteStrToBool; 590 685 end; 591 686 end; … … 620 715 else if Command is TContinue then ExecuteContinue(Block, TContinue(Command)) 621 716 else if Command is TEmptyCommand then 622 else raise Exception.Create( 'Unsupported command type');717 else raise Exception.Create(SUnsupportedCommandType); 623 718 end; 624 719 … … 635 730 ExecuteCommand(Block, IfThenElse.CommandElse); 636 731 end; 637 end else raise Exception.Create( 'Expected boolean value.');732 end else raise Exception.Create(SExpectedBooleanValue); 638 733 Value.Free; 639 734 end; … … 659 754 Break; 660 755 end; 661 end else raise Exception.Create( 'Expected boolean value.');756 end else raise Exception.Create(SExpectedBooleanValue); 662 757 end; 663 758 end; … … 687 782 Value.Free; 688 783 if BoolValue then Break; 689 end else raise Exception.Create( 'Expected boolean value.');784 end else raise Exception.Create(SExpectedBooleanValue); 690 785 end; 691 786 end; … … 760 855 var 761 856 ExecutorFunction: TExecutorFunction; 762 Params: array of T Value;857 Params: array of TExecutorFunctionCallbackParam; 763 858 I: Integer; 764 859 ExecutorVariable: TExecutorVariable; … … 771 866 SetLength(Params, FunctionCall.Params.Count); 772 867 for I := 0 to FunctionCall.Params.Count - 1 do begin 773 Params[I] := ExecuteExpression(Block, TExpression(FunctionCall.Params[0])); 868 Params[I] := TExecutorFunctionCallbackParam.Create; 869 Params[I].Kind := FunctionCall.FunctionDef.Params[I].Kind; 870 if FunctionCall.FunctionDef.Params[I].Kind = pkVar then begin 871 Variable := TExpressionOperand(FunctionCall.Params[I]).VariableRef; 872 //InitExecutorBlock(ExecutorFunction.Block, FunctionCall.FunctionDef.Block); 873 ExecutorVariable := Block.GetVariable(Variable); 874 Params[I].Variable := ExecutorVariable; 875 end 876 else Params[I].Value := ExecuteExpression(Block, FunctionCall.Params[I]); 774 877 end; 775 878 Result := ExecutorFunction.Callback(Params); 776 879 for I := 0 to FunctionCall.Params.Count - 1 do begin 880 //if FunctionCall.Params[I]. 777 881 Params[I].Free; 778 882 end; … … 798 902 Variable: TExecutorVariable; 799 903 ExecutorFunction: TExecutorFunction; 800 Params: array of T Value;904 Params: array of TExecutorFunctionCallbackParam; 801 905 begin 802 906 Value := ExecuteExpression(Block, Assignment.Expression); … … 805 909 if Assignment.Variable.TypeRef = Assignment.Expression.GetType then begin; 806 910 SetLength(Params, 1); 807 Params[0] := Value; 911 Params[0] := TExecutorFunctionCallbackParam.Create; 912 Params[0].Value := Value; 808 913 Variable.Value.Free; 809 914 Variable.Value := ExecutorFunction.Callback(Params); … … 834 939 Value: TValue; 835 940 ExecutorFunction: TExecutorFunction; 836 Params: array of T Value;941 Params: array of TExecutorFunctionCallbackParam; 837 942 FuncName: string; 838 943 begin … … 846 951 for I := 0 to Expression.Items.Count - 1 do begin 847 952 Value := ExecuteExpression(Block, TExpression(Expression.Items[I])); 848 Params[I] := Value; 953 Params[I] := TExecutorFunctionCallbackParam.Create; 954 Params[I].Value := Value; 849 955 end; 850 956 Result := ExecutorFunction.Callback(Params); … … 862 968 otConstantRef: Result := Expression.ConstantRef.Value.Clone; 863 969 otVariableRef: Result := Block.Variables.SearchByVariable(Expression.VariableRef).Value.Clone; 864 else raise Exception.Create( 'Unsupported exception operand type.');970 else raise Exception.Create(SUnsupportedOperandType); 865 971 end; 866 972 end; … … 883 989 end; 884 990 991 function TExecutor.Input: string; 992 begin 993 if Assigned(FOnInput) then 994 Result := FOnInput; 995 end; 996 885 997 end. 886 998
Note:
See TracChangeset
for help on using the changeset viewer.