Changeset 99 for branches/interpreter/Execute3.pas
- Timestamp:
- Feb 6, 2017, 12:11:54 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter/Execute3.pas
r98 r99 5 5 uses 6 6 Source3; 7 8 type 9 TVariableValue = record 10 BaseType: TBaseType; 11 case Integer of 12 0: (ValueChar: Char); 13 1: (ValueInteger: Integer); 14 2: (ValueString: ShortString); 15 3: (ValueBoolean: Boolean); 16 end; 17 PVariableValue = ^TVariableValue; 18 19 TVariableValues = record 20 Items: array of TVariableValue; 21 end; 22 23 { TExecutionContext } 24 25 TExecutionContext = record 26 VariableValues: TVariableValues; 27 procedure LoadFromVariables(Variables: PVariables); 28 end; 29 PExecutionContext = ^TExecutionContext; 30 31 { TExecutionContexts } 32 33 TExecutionContexts = record 34 Items: array of TExecutionContext; 35 function Last: PExecutionContext; 36 procedure Add; 37 procedure RemoveLast; 38 end; 39 40 var 41 ExecutionContexts: TExecutionContexts; 7 42 8 43 procedure ExecuteProgram(ProgramCode: PProgramCode); … … 43 78 I: Integer; 44 79 begin 80 ExecutionContexts.Add; 81 ExecutionContexts.Last^.LoadFromVariables(@Execution^.Func^.Variables); 45 82 { Execution^.Func^.Variables.Add(VariableCreate('Result', Execution^.Func^.ReturnType)); 46 83 for I := 0 to Length(Execution^.Func^.Parameters.Items) - 1 do begin … … 53 90 } 54 91 ExecuteBeginEnd(@Execution^.Func^.BeginEnd); 92 ExecutionContexts.RemoveLast; 55 93 end; 56 94 57 95 procedure ExecuteAssignment(Assignment: PAssignment); 96 var 97 DestVariable: PVariableValue; 58 98 begin 59 case Assignment^.Destination^.DataType^.BaseType of 60 btBoolean: Assignment^.Destination.ValueBoolean := ExecuteExpressionBoolean(@Assignment^.Source); 99 DestVariable := @ExecutionContexts.Last^.VariableValues.Items[Assignment^.Destination^.Index]; 100 case DestVariable^.BaseType of 101 btBoolean: DestVariable^.ValueBoolean := ExecuteExpressionBoolean(@Assignment^.Source); 61 102 //btChar: Assignment^.Destination.ValueBoolean := ExecuteExpressionChar(@Assignment^.Source); 62 103 //btString: Assignment^.Destination.ValueBoolean := ExecuteExpressionString(@Assignment^.Source); … … 78 119 procedure ExecuteProgram(ProgramCode: PProgramCode); 79 120 begin 121 SetLength(ExecutionContexts.Items, 1); 122 ExecutionContexts.Last^.LoadFromVariables(@ProgramCode^.Variables); 80 123 ExecuteBeginEnd(@ProgramCode^.BeginEnd); 124 end; 125 126 { TExecutionContext } 127 128 procedure TExecutionContext.LoadFromVariables(Variables: PVariables); 129 var 130 I: Integer; 131 begin 132 SetLength(VariableValues.Items, Length(Variables.Items)); 133 for I := 0 to Length(Variables.Items) - 1 do begin 134 VariableValues.Items[I].BaseType := Variables.Items[I].DataType.BaseType; 135 end; 136 end; 137 138 { TExecutionContexts } 139 140 function TExecutionContexts.Last: PExecutionContext; 141 begin 142 Result := @ExecutionContexts.Items[Length(ExecutionContexts.Items) - 1]; 143 end; 144 145 procedure TExecutionContexts.Add; 146 begin 147 SetLength(Items, Length(Items) + 1); 148 end; 149 150 procedure TExecutionContexts.RemoveLast; 151 begin 152 SetLength(Items, Length(Items) - 1); 81 153 end; 82 154
Note:
See TracChangeset
for help on using the changeset viewer.