Changeset 222 for branches/interpreter2/UExecutor.pas
- Timestamp:
- Nov 25, 2020, 12:18:45 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter2/UExecutor.pas
r221 r222 92 92 function ExecuteStrToInt(Params: array of TValue): TValue; 93 93 function ExecuteBooleanAssign(Params: array of TValue): TValue; 94 function ExecuteBooleanNot(Params: array of TValue): TValue; 94 95 function ExecuteBooleanEqual(Params: array of TValue): TValue; 95 96 function ExecuteBooleanNotEqual(Params: array of TValue): TValue; … … 101 102 function ExecuteIntegerAdd(Params: array of TValue): TValue; 102 103 function ExecuteIntegerSub(Params: array of TValue): TValue; 104 function ExecuteIntegerMul(Params: array of TValue): TValue; 105 function ExecuteIntegerIntDiv(Params: array of TValue): TValue; 106 function ExecuteIntegerMod(Params: array of TValue): TValue; 103 107 function ExecuteIntegerEqual(Params: array of TValue): TValue; 104 108 function ExecuteIntegerNotEqual(Params: array of TValue): TValue; 109 function ExecuteIntegerLesser(Params: array of TValue): TValue; 110 function ExecuteIntegerHigher(Params: array of TValue): TValue; 111 function ExecuteIntegerLesserOrEqual(Params: array of TValue): TValue; 112 function ExecuteIntegerHigherOrEqual(Params: array of TValue): TValue; 113 function ExecuteIntegerAnd(Params: array of TValue): TValue; 114 function ExecuteIntegerOr(Params: array of TValue): TValue; 115 function ExecuteIntegerXor(Params: array of TValue): TValue; 116 function ExecuteIntegerShr(Params: array of TValue): TValue; 117 function ExecuteIntegerShl(Params: array of TValue): TValue; 105 118 procedure InitExecutorBlock(ExecutorBlock: TExecutorBlock; Block: TBlock); 106 119 public … … 121 134 function ExecuteExpressionOperation(Block: TExecutorBlock; Expression: TExpressionOperation): TValue; 122 135 function ExecuteExpressionOperand(Block: TExecutorBlock; Expression: TExpressionOperand): TValue; 136 function ExecuteExpressionBrackets(Block: TExecutorBlock; Expression: TExpressionBrackets): TValue; 123 137 procedure Run; 124 138 procedure Output(Text: string); … … 323 337 end; 324 338 339 function TExecutor.ExecuteBooleanNot(Params: array of TValue): TValue; 340 begin 341 Result := TValueBoolean.Create; 342 TValueBoolean(Result).Value := not TValueBoolean(Params[0]).Value; 343 end; 344 325 345 function TExecutor.ExecuteBooleanEqual(Params: array of TValue): TValue; 326 346 begin … … 377 397 end; 378 398 399 function TExecutor.ExecuteIntegerMul(Params: array of TValue): TValue; 400 begin 401 Result := TValueInteger.Create; 402 TValueInteger(Result).Value := TValueInteger(Params[0]).Value * TValueInteger(Params[1]).Value; 403 end; 404 405 function TExecutor.ExecuteIntegerIntDiv(Params: array of TValue): TValue; 406 begin 407 Result := TValueInteger.Create; 408 TValueInteger(Result).Value := TValueInteger(Params[0]).Value div TValueInteger(Params[1]).Value; 409 end; 410 411 function TExecutor.ExecuteIntegerMod(Params: array of TValue): TValue; 412 begin 413 Result := TValueInteger.Create; 414 TValueInteger(Result).Value := TValueInteger(Params[0]).Value mod TValueInteger(Params[1]).Value; 415 end; 416 379 417 function TExecutor.ExecuteIntegerEqual(Params: array of TValue): TValue; 380 418 begin … … 387 425 Result := TValueBoolean.Create; 388 426 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value <> TValueInteger(Params[1]).Value; 427 end; 428 429 function TExecutor.ExecuteIntegerLesser(Params: array of TValue): TValue; 430 begin 431 Result := TValueBoolean.Create; 432 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value < TValueInteger(Params[1]).Value; 433 end; 434 435 function TExecutor.ExecuteIntegerHigher(Params: array of TValue): TValue; 436 begin 437 Result := TValueBoolean.Create; 438 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value > TValueInteger(Params[1]).Value; 439 end; 440 441 function TExecutor.ExecuteIntegerLesserOrEqual(Params: array of TValue): TValue; 442 begin 443 Result := TValueBoolean.Create; 444 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value <= TValueInteger(Params[1]).Value; 445 end; 446 447 function TExecutor.ExecuteIntegerHigherOrEqual(Params: array of TValue): TValue; 448 begin 449 Result := TValueBoolean.Create; 450 TValueBoolean(Result).Value := TValueInteger(Params[0]).Value >= TValueInteger(Params[1]).Value; 451 end; 452 453 function TExecutor.ExecuteIntegerAnd(Params: array of TValue): TValue; 454 begin 455 Result := TValueInteger.Create; 456 TValueInteger(Result).Value := TValueInteger(Params[0]).Value and TValueInteger(Params[1]).Value; 457 end; 458 459 function TExecutor.ExecuteIntegerOr(Params: array of TValue): TValue; 460 begin 461 Result := TValueInteger.Create; 462 TValueInteger(Result).Value := TValueInteger(Params[0]).Value or TValueInteger(Params[1]).Value; 463 end; 464 465 function TExecutor.ExecuteIntegerXor(Params: array of TValue): TValue; 466 begin 467 Result := TValueInteger.Create; 468 TValueInteger(Result).Value := TValueInteger(Params[0]).Value xor TValueInteger(Params[1]).Value; 469 end; 470 471 function TExecutor.ExecuteIntegerShr(Params: array of TValue): TValue; 472 begin 473 Result := TValueInteger.Create; 474 TValueInteger(Result).Value := TValueInteger(Params[0]).Value shr TValueInteger(Params[1]).Value; 475 end; 476 477 function TExecutor.ExecuteIntegerShl(Params: array of TValue): TValue; 478 begin 479 Result := TValueInteger.Create; 480 TValueInteger(Result).Value := TValueInteger(Params[0]).Value shl TValueInteger(Params[1]).Value; 389 481 end; 390 482 … … 410 502 ExecutorFunction.Callback := ExecuteBooleanNotEqual; 411 503 end; 504 if ExecutorFunction.FunctionDef.Name = '_Not' then begin 505 ExecutorFunction.Callback := ExecuteBooleanNot; 506 end else 412 507 end else 413 508 if ExecutorType.TypeRef.Name = 'string' then begin … … 435 530 ExecutorFunction.Callback := ExecuteIntegerSub; 436 531 end else 532 if ExecutorFunction.FunctionDef.Name = '_Mul' then begin 533 ExecutorFunction.Callback := ExecuteIntegerMul; 534 end else 535 if ExecutorFunction.FunctionDef.Name = '_IntDiv' then begin 536 ExecutorFunction.Callback := ExecuteIntegerIntDiv; 537 end else 538 if ExecutorFunction.FunctionDef.Name = '_IntMod' then begin 539 ExecutorFunction.Callback := ExecuteIntegerMod; 540 end else 437 541 if ExecutorFunction.FunctionDef.Name = '_Equal' then begin 438 542 ExecutorFunction.Callback := ExecuteIntegerEqual; … … 440 544 if ExecutorFunction.FunctionDef.Name = '_NotEqual' then begin 441 545 ExecutorFunction.Callback := ExecuteIntegerNotEqual; 546 end; 547 if ExecutorFunction.FunctionDef.Name = '_Lesser' then begin 548 ExecutorFunction.Callback := ExecuteIntegerLesser; 549 end else 550 if ExecutorFunction.FunctionDef.Name = '_Higher' then begin 551 ExecutorFunction.Callback := ExecuteIntegerHigher; 552 end; 553 if ExecutorFunction.FunctionDef.Name = '_LesserOrEqual' then begin 554 ExecutorFunction.Callback := ExecuteIntegerLesserOrEqual; 555 end else 556 if ExecutorFunction.FunctionDef.Name = '_HigherOrEqual' then begin 557 ExecutorFunction.Callback := ExecuteIntegerHigherOrEqual; 558 end; 559 if ExecutorFunction.FunctionDef.Name = '_And' then begin 560 ExecutorFunction.Callback := ExecuteIntegerAnd; 561 end; 562 if ExecutorFunction.FunctionDef.Name = '_Or' then begin 563 ExecutorFunction.Callback := ExecuteIntegerOr; 564 end; 565 if ExecutorFunction.FunctionDef.Name = '_Xor' then begin 566 ExecutorFunction.Callback := ExecuteIntegerXor; 567 end; 568 if ExecutorFunction.FunctionDef.Name = '_Shr' then begin 569 ExecutorFunction.Callback := ExecuteIntegerShr; 570 end; 571 if ExecutorFunction.FunctionDef.Name = '_Shl' then begin 572 ExecutorFunction.Callback := ExecuteIntegerShl; 442 573 end; 443 574 end; … … 692 823 if Expression is TExpressionOperand then 693 824 Result := ExecuteExpressionOperand(Block, TExpressionOperand(Expression)) 694 else raise Exception.Create('Unknown expression class.'); 825 else 826 if Expression is TExpressionBrackets then 827 Result := ExecuteExpressionBrackets(Block, TExpressionBrackets(Expression)) 828 else 829 raise Exception.Create('Unknown expression class.'); 695 830 end; 696 831 … … 733 868 end; 734 869 870 function TExecutor.ExecuteExpressionBrackets(Block: TExecutorBlock; 871 Expression: TExpressionBrackets): TValue; 872 begin 873 Result := ExecuteExpression(Block, Expression.Expression); 874 end; 875 735 876 procedure TExecutor.Run; 736 877 begin
Note:
See TracChangeset
for help on using the changeset viewer.