Changeset 203 for branches/interpreter2/UExecutor.pas
- Timestamp:
- Apr 17, 2020, 10:16:25 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter2/UExecutor.pas
r202 r203 10 10 type 11 11 TExecutorFunctions = class; 12 13 { TExecutorVariable } 12 14 13 15 TExecutorVariable = class 14 16 Variable: TVariable; 15 17 Value: TValue; 18 constructor Create; 19 destructor Destroy; override; 16 20 end; 17 21 … … 99 103 procedure ExecuteWhileDo(Block: TExecutorBlock; WhileDo: TWhileDo); 100 104 procedure ExecuteForToDo(Block: TExecutorBlock; ForToDo: TForToDo); 101 procedure ExecuteBlock(ParentBlock: TExecutorBlock; Block: TBlock);105 procedure ExecuteBlock(ParentBlock: TExecutorBlock; Block: TBlock); 102 106 function ExecuteFunctionCall(Block: TExecutorBlock; FunctionCall: TFunctionCall): TValue; 103 107 procedure ExecuteAssignment(Block: TExecutorBlock; Assignment: TAssignment); … … 112 116 113 117 implementation 118 119 { TExecutorVariable } 120 121 constructor TExecutorVariable.Create; 122 begin 123 Value := TValue.Create; 124 end; 125 126 destructor TExecutorVariable.Destroy; 127 begin 128 Value.Free; 129 inherited Destroy; 130 end; 114 131 115 132 { TExecutorType } … … 429 446 else ExecuteCommand(Block, IfThenElse.CommandElse); 430 447 end else raise Exception.Create('Expected boolean value.'); 448 Value.Free; 431 449 end; 432 450 … … 441 459 ExecuteCommand(Block, WhileDo.Command); 442 460 end else raise Exception.Create('Expected boolean value.'); 461 Value.Free; 443 462 end; 444 463 end; … … 446 465 procedure TExecutor.ExecuteForToDo(Block: TExecutorBlock; ForToDo: TForToDo); 447 466 var 448 Value: TValue;449 467 Variable: TExecutorVariable; 450 468 Limit: TValue; 451 469 begin 452 470 Variable := Block.GetVariable(ForToDo.VariableRef); 471 Variable.Value.Free; 453 472 Variable.Value := ExecuteExpression(Block, ForToDo.ExpressionFrom); 454 473 Limit := ExecuteExpression(Block, ForToDo.ExpressionTo); … … 458 477 if TValueInteger(Variable.Value).Value > TValueInteger(Limit).Value then Break; 459 478 end; 479 Limit.Free; 460 480 end; 461 481 … … 486 506 end; 487 507 Result := ExecutorFunction.Callback(Params); 508 for I := 0 to FunctionCall.Params.Count - 1 do begin 509 Params[I].Free; 510 end; 488 511 end else raise Exception.Create('No executor for ' + FunctionCall.FunctionDef.Name + ' function.'); 489 512 end; … … 503 526 SetLength(Params, 1); 504 527 Params[0] := Value; 528 Variable.Value.Free; 505 529 Variable.Value := ExecutorFunction.Callback(Params); 506 530 end else raise Exception('Assignment result type is ' + Variable.Variable.TypeRef.Name + 507 531 ' but value is ' + Assignment.Expression.GetType.Name + '.'); 532 Value.Free; 508 533 end; 509 534 … … 543 568 end; 544 569 Result := ExecutorFunction.Callback(Params); 570 for I := 0 to Expression.Items.Count - 1 do begin 571 Params[I].Free; 572 end; 545 573 end; 546 574 … … 548 576 Expression: TExpressionOperand): TValue; 549 577 begin 550 if Assigned(Expression.VariableRef) then begin 551 Result := Block.Variables.SearchByVariable(Expression.VariableRef).Value; 552 end else 553 if Assigned(Expression.ConstantRef) then begin 554 Result := Expression.ConstantRef.Value; 555 end else 556 if Assigned(Expression.FunctionCall) then begin 557 Result := ExecuteFunctionCall(Block, Expression.FunctionCall); 558 end else raise Exception.Create('Unsupported exception operand type.'); 578 case Expression.OperandType of 579 otFunctionCall: Result := ExecuteFunctionCall(Block, Expression.FunctionCall); 580 otConstantDirect: Result := Expression.ConstantDirect.Value.Clone; 581 otConstantRef: Result := Expression.ConstantRef.Value.Clone; 582 otVariableRef: Result := Block.Variables.SearchByVariable(Expression.VariableRef).Value.Clone; 583 else raise Exception.Create('Unsupported exception operand type.'); 584 end; 559 585 end; 560 586
Note:
See TracChangeset
for help on using the changeset viewer.