- Timestamp:
- Jan 4, 2018, 2:00:49 PM (7 years ago)
- Location:
- branches/virt simple
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/virt simple/UCompiler.pas
r90 r138 47 47 Param2: string; 48 48 ParamType1: TParamType; 49 Indirect1: Boolean;49 Indirect1: TMemoryType; 50 50 Value1: Integer; 51 51 ParamType2: TParamType; 52 Indirect2: Boolean;52 Indirect2: TMemoryType; 53 53 Value2: Integer; 54 54 OutValue: Integer; … … 74 74 if Param1 <> '' then begin 75 75 if (Copy(Param1, 1, 1) = '[') and (Copy(Param1, Length(Param1), 1) = ']') then begin 76 Indirect1 := True;76 Indirect1 := mtData; 77 77 Param1 := Trim(Copy(Param1, 2, Length(Param1) - 2)); 78 end else Indirect1 := False;78 end else Indirect1 := mtNone; 79 79 if Copy(Param1, 1, 1) = 'R' then begin 80 80 ParamType1 := ptRegister; … … 103 103 if Param2 <> '' then begin 104 104 if (Copy(Param2, 1, 1) = '[') and (Copy(Param2, Length(Param2), 1) = ']') then begin 105 Indirect2 := True;105 Indirect2 := mtData; 106 106 Param2 := Trim(Copy(Param2, 2, Length(Param2) - 2)); 107 end else Indirect2 := False;107 end else Indirect2 := mtNone; 108 108 if Copy(Param2, 1, 1) = 'R' then begin 109 109 ParamType2 := ptRegister; -
branches/virt simple/UFormMain.lfm
r89 r138 1 1 object Form1: TForm1 2 Left = 3833 Height = 1 1044 Top = 1915 Width = 170 82 Left = 44 3 Height = 1023 4 Top = 6 5 Width = 1703 6 6 Caption = 'Form1' 7 ClientHeight = 1104 8 ClientWidth = 1708 7 ClientHeight = 0 8 ClientWidth = 0 9 DesignTimePPI = 120 9 10 OnClose = FormClose 10 11 OnCreate = FormCreate 11 12 OnDestroy = FormDestroy 12 13 OnShow = FormShow 13 LCLVersion = '1. 7'14 LCLVersion = '1.8.0.6' 14 15 object ListViewMemory: TListView 15 16 Left = 888 … … 77 78 object Label1: TLabel 78 79 Left = 888 79 Height = 2 480 Height = 20 80 81 Top = 9 81 Width = 7582 Width = 58 82 83 Caption = 'Memory:' 83 84 ParentColor = False … … 85 86 object Label2: TLabel 86 87 Left = 1128 87 Height = 2 488 Height = 20 88 89 Top = 9 89 Width = 8490 Width = 63 90 91 Caption = 'Registers:' 91 92 ParentColor = False … … 93 94 object Label3: TLabel 94 95 Left = 1416 95 Height = 2 496 Height = 20 96 97 Top = 8 97 Width = 1 4598 Width = 111 98 99 Caption = 'Special registers:' 99 100 ParentColor = False … … 131 132 object Label4: TLabel 132 133 Left = 18 133 Height = 2 4134 Height = 20 134 135 Top = 744 135 Width = 66136 Width = 49 136 137 Caption = 'Output:' 137 138 ParentColor = False … … 139 140 object Label5: TLabel 140 141 Left = 528 141 Height = 2 4142 Height = 20 142 143 Top = 9 143 Width = 1 94144 Width = 152 144 145 Caption = 'Compiled source code:' 145 146 ParentColor = False … … 157 158 object Label6: TLabel 158 159 Left = 20 159 Height = 2 4160 Height = 20 160 161 Top = 7 161 Width = 109162 Width = 85 162 163 Caption = 'Source code:' 163 164 ParentColor = False -
branches/virt simple/UMachine.pas
r89 r138 24 24 TParamType = (ptNone, ptConst, ptRegister, ptSpecialRegister); 25 25 TCondition = (cdZero, cdNotZero, cdNegative, cdPositive); 26 TMemoryType = (mtNone, mtData); 26 27 27 28 TValue = Integer; … … 33 34 TParam = class 34 35 ParamType: TParamType; 35 Memory : Boolean;36 MemoryType: TMemoryType; 36 37 Value: TValue; 37 38 function GetString: string; 39 procedure SetParam(ParamType: TParamType; MemoryType: TMemoryType; Value: TValue); 38 40 end; 39 41 … … 51 53 procedure AddInst(Opcode: TOpcode); overload; 52 54 procedure AddInst(Opcode: TOpcode; 53 ParamType1: TParamType; Indirect1: Boolean; Value1: TValue); overload;55 ParamType1: TParamType; Indirect1: TMemoryType; Value1: TValue); overload; 54 56 procedure AddInst(Opcode: TOpcode; 55 ParamType1: TParamType; Indirect1: Boolean; Value1: TValue;56 ParamType2: TParamType; Indirect2: Boolean; Value2: TValue); overload;57 ParamType1: TParamType; Indirect1: TMemoryType; Value1: TValue; 58 ParamType2: TParamType; Indirect2: TMemoryType; Value2: TValue); overload; 57 59 end; 58 60 … … 146 148 else Result := 'S' + IntToStr(Value); 147 149 end; 148 if Memory then Result := '[' + Result + ']'; 150 if MemoryType = mtData then Result := '[' + Result + ']'; 151 end; 152 153 procedure TParam.SetParam(ParamType: TParamType; MemoryType: TMemoryType; 154 Value: TValue); 155 begin 156 Self.ParamType := ParamType; 157 Self.MemoryType := MemoryType; 158 Self.Value := Value; 149 159 end; 150 160 … … 183 193 NewInst := TInstruction.Create; 184 194 NewInst.Opcode := Opcode; 185 NewInst.Params[0].ParamType := ptNone; 186 NewInst.Params[0].Memory := False; 187 NewInst.Params[0].Value := 0; 188 NewInst.Params[1].ParamType := ptNone; 189 NewInst.Params[1].Memory := False; 190 NewInst.Params[1].Value := 0; 195 NewInst.Params[0].SetParam(ptNone, mtNone, 0); 196 NewInst.Params[1].SetParam(ptNone, mtNone, 0); 191 197 Add(NewInst); 192 198 end; 193 199 194 200 procedure TInstructions.AddInst(Opcode: TOpcode; ParamType1: TParamType; 195 Indirect1: Boolean; Value1: TValue);201 Indirect1: TMemoryType; Value1: TValue); 196 202 var 197 203 NewInst: TInstruction; … … 199 205 NewInst := TInstruction.Create; 200 206 NewInst.Opcode := Opcode; 201 NewInst.Params[0].ParamType := ParamType1; 202 NewInst.Params[0].Memory := Indirect1; 203 NewInst.Params[0].Value := Value1; 204 NewInst.Params[1].ParamType := ptNone; 205 NewInst.Params[1].Memory := False; 206 NewInst.Params[1].Value := 0; 207 NewInst.Params[0].SetParam(ParamType1, Indirect1, Value1); 208 NewInst.Params[1].SetParam(ptNone, mtNone, 0); 207 209 Add(NewInst); 208 210 end; 209 211 210 212 procedure TInstructions.AddInst(Opcode: TOpcode; 211 ParamType1: TParamType; Indirect1: Boolean; Value1: TValue;212 ParamType2: TParamType; Indirect2: Boolean; Value2: TValue);213 ParamType1: TParamType; Indirect1: TMemoryType; Value1: TValue; 214 ParamType2: TParamType; Indirect2: TMemoryType; Value2: TValue); 213 215 var 214 216 NewInst: TInstruction; … … 216 218 NewInst := TInstruction.Create; 217 219 NewInst.Opcode := Opcode; 218 NewInst.Params[0].ParamType := ParamType1; 219 NewInst.Params[0].Memory := Indirect1; 220 NewInst.Params[0].Value := Value1; 221 NewInst.Params[1].ParamType := ParamType2; 222 NewInst.Params[1].Memory := Indirect2; 223 NewInst.Params[1].Value := Value2; 220 NewInst.Params[0].SetParam(ParamType1, Indirect1, Value1); 221 NewInst.Params[1].SetParam(ParamType2, Indirect2, Value2); 224 222 Add(NewInst); 225 223 end; … … 469 467 end else if Param.ParamType = ptNone then raise Exception.Create('Read from not set parameter') 470 468 else raise Exception.Create('Unsupported parameter type ' + IntToStr(Integer(Param.ParamType))); 471 if Param.Memory then Result := Memory[Result];469 if Param.MemoryType = mtData then Result := Memory[Result]; 472 470 end; 473 471 … … 475 473 begin 476 474 if Param.ParamType = ptRegister then begin 477 if Param.Memory then Memory[Registers[Param.Value]] := Value475 if Param.MemoryType = mtData then Memory[Registers[Param.Value]] := Value 478 476 else Registers[Param.Value] := Value; 479 end else if Param.ParamType = ptConst then begin 480 if Param.Memory then Memory[Param.Value] := Value 477 end else 478 if Param.ParamType = ptConst then begin 479 if Param.MemoryType = mtData then Memory[Param.Value] := Value 481 480 else raise Exception.Create('Cannot assign to constant parameter'); 482 end else if Param.ParamType = ptSpecialRegister then begin 481 end else 482 if Param.ParamType = ptSpecialRegister then begin 483 483 if Param.Value = Integer(srIP) then begin 484 if Param.Memory then Memory[IP] := Value484 if Param.MemoryType = mtData then Memory[IP] := Value 485 485 else IP := Value; 486 486 end else if Param.Value = Integer(srSP) then begin 487 if Param.Memory then Memory[SP] := Value487 if Param.MemoryType = mtData then Memory[SP] := Value 488 488 else SP := Value; 489 489 end else raise Exception.Create('Unsupported special register ' + IntToStr(Integer(Param.Value))); 490 end else if Param.ParamType = ptNone then raise Exception.Create('Write to not set parameter') 491 else raise Exception.Create('Unsupported parameter type ' + IntToStr(Integer(Param.ParamType))); 490 end else 491 if Param.ParamType = ptNone then begin 492 raise Exception.Create('Write to not set parameter') 493 end else 494 raise Exception.Create('Unsupported parameter type ' + IntToStr(Integer(Param.ParamType))); 492 495 end; 493 496 -
branches/virt simple/project1.lpi
r88 r138 2 2 <CONFIG> 3 3 <ProjectOptions> 4 <Version Value=" 9"/>4 <Version Value="10"/> 5 5 <General> 6 6 <SessionStorage Value="InProjectDir"/> … … 11 11 <Icon Value="0"/> 12 12 </General> 13 <VersionInfo>14 <StringTable ProductVersion=""/>15 </VersionInfo>16 13 <BuildModes Count="1"> 17 14 <Item1 Name="Default" Default="True"/>
Note:
See TracChangeset
for help on using the changeset viewer.